forked from kdn251/interviews
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
7 additions
and
7 deletions.
There are no files selected for viewing
6 changes: 3 additions & 3 deletions
6
CrackingTheCodingInterview/Chapter1ArraysAndStrings/IsUniqueChars.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,15 @@ | ||
//Implement an algorithm to determine if a string has all unique characters. What if you cannot use additional data structures? | ||
|
||
public class isUniqueChars { | ||
public class IsUniqueChars { | ||
public boolean isUniqueChars(String str) { | ||
int checker = 0; | ||
for(int i = 0; i < str.length(); i++) { | ||
int val = str.charAt(i) - 'a'; | ||
if((checker & (1 << val)) > 0) { | ||
return false; | ||
} | ||
checker |= (1 << val)); | ||
checker |= (1 << val); | ||
} | ||
return true; | ||
} | ||
} | ||
} |
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
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