lintcode-easy-Unique Characters
Implement an algorithm to determine if a string has all unique characters.
Given "abc"
, return true
.
Given "aab"
, return false
.
public class Solution { /** * @param str: a string * @return: a boolean */ public boolean isUnique(String str) { // write your code here if(str == null || str.length() == 0) return true; int[] ch = new int[128]; for(int i = 0; i < str.length(); i++){ ch[str.charAt(i)]++; if(ch[str.charAt(i)] > 1) return false; } return true; } }