Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class que1_array_unique {
- public static boolean isUnique(String str) {
- boolean[] char_set = new boolean[256];
- for (int i = 0; i < str.length(); i++) {
- int val = str.charAt(i);
- if (char_set[val]) return false;
- char_set[val] = true;
- }
- return true;
- }
- public static void main(String[] args) {
- String[] words = {"abcde", "hello", "apple", "kite", "padle"};
- System.out.println("It will print true for Unique Characters\n");
- for (String word : words) {
- System.out.println(word + ": " + isUnique(word)+"\n");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment