/*
 * Copyright (C) 2014 Pedro Vicente Gómez Sánchez.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.github.pedrovgs.problem50;

/**
 * Implement an algorithm to determine if a string has all unique characters. What if you cannot
 * use additional data structures?
 *
 * @author Pedro Vicente Gómez Sánchez.
 */
public class UniqueChars {
  public boolean evaluate(String input) {
    return false;
  }
}

@@ -645,16 +645,65 @@
 lem50;%0A%0A
+import java.util.HashMap;%0Aimport java.util.Map;%0A%0A
 /**%0A * I
@@ -908,67 +908,1260 @@
 s %7B%0A
-  public boolean evaluate(String input) %7B%0A    return false;
+%0A  /**%0A   * Iterative algorithm to solve this problem. The complexity order of this algorithm in space an%0A   * time terms is equals to O(N) where N is the number of chars inside the input String passed as%0A   * parameter.%0A   */%0A  public boolean evaluate(String input) %7B%0A    validateInput(input);%0A    Map%3CString, Integer%3E chars = countCharAppearances(input);%0A    return containsDuplicatedChars(chars);%0A  %7D%0A%0A  private Map%3CString, Integer%3E countCharAppearances(String input) %7B%0A    Map%3CString, Integer%3E chars = new HashMap%3CString, Integer%3E();%0A    for (char c : input.toCharArray()) %7B%0A      countChar(chars, String.valueOf(c));%0A    %7D%0A    return chars;%0A  %7D%0A%0A  private void countChar(Map%3CString, Integer%3E chars, String c) %7B%0A    Integer newCount = chars.containsKey(c) ? chars.get(c) + 1 : 1;%0A    chars.put(c, newCount);%0A  %7D%0A%0A  private boolean containsDuplicatedChars(Map%3CString, Integer%3E chars) %7B%0A    boolean duplicatedChar = false;%0A    for (Integer counter : chars.values()) %7B%0A      if (counter %3E 1) %7B%0A        duplicatedChar = true;%0A        break;%0A      %7D%0A    %7D%0A    return duplicatedChar;%0A  %7D%0A%0A  private void validateInput(String input) %7B%0A    if (input == null) %7B%0A      throw new IllegalArgumentException(%22You can't pass a null instance as parameter.%22);%0A    %7D
 %0A  %7D

Add solution to problem 50