Last active
August 29, 2015 14:27
-
-
Save reza-ryte-club/8ea0e79c40b1b7f481b1 to your computer and use it in GitHub Desktop.
Check whether a string has uniqe 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
package com.company; | |
public class Unique { | |
public static boolean checkUnique(String word){ | |
if(word.length()>256) return false;// if a string is more than 256 characters long, it repeats any of the string | |
boolean[] charset = new boolean[256]; | |
for(int i = 0;i<word.length();i++){ | |
char c = word.charAt(i); | |
if(charset[c]) return false; | |
charset[c]=true; | |
} | |
return true; | |
} | |
public static void main(String[] args) { | |
System.out.println(checkUnique("Helow")); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment