Last active
August 29, 2015 14:05
-
-
Save XinboChen/5d655fb0b2999924d61e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Implement an algorithm to determine if a string has all unique characters what if you can't use additional data structure | |
Date: 08/26/2014 | |
*/ | |
class solution{ | |
// Time complexity O(n^2), Space complexity O(1) | |
public boolean check( String s ){ | |
boolean result = true; | |
if( s.length() < 2 )// include string is empty | |
result = true; | |
int i, j; | |
for( i = 0; i < s.length() - 1; i ++){ | |
for(j = i + 1; j < s.length(); j ++){ | |
if(s.charAt( i ) == s.charAt( j ) // charAt(int index) return a character of a string in position index. | |
result = false; | |
break; | |
} | |
return true; | |
} | |
return result; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment