@Test public void testIsUnique() { assertTrue(isUnique("abc")); assertFalse(isUnique("aba")); }
public static boolean isUnique(String s) { int[] arr = new int[3]; int len = s.length(); int ch = -1; final int numASCIICtrlChars = 32; for (int i = 0; i < len; i++) { ch = s.charAt(i) - numASCIICtrlChars; int bitmask = ch & 0x1f; int bitVectorIdx = ch >> 5; ch = arr[bitVectorIdx] & bitmask; if (ch == 1) { return false; } arr[bitVectorIdx] |= bitmask; } return true; }
PracticeQuestionsCh1 { public static boolean isUnique(String s) { int[] arr = new int[3]; int len = s.length(); int ch = -1; final int numASCIICtrlChars = 32; for (int i = 0; i < len; i++) { ch = s.charAt(i) - numASCIICtrlChars; int bitmask = ch & 0x1f; int bitVectorIdx = ch >> 5; ch = arr[bitVectorIdx] & bitmask; if (ch == 1) { return false; } arr[bitVectorIdx] |= bitmask; } return true; } }
PracticeQuestionsCh1 { public static boolean isUnique(String s) { int[] arr = new int[3]; int len = s.length(); int ch = -1; final int numASCIICtrlChars = 32; for (int i = 0; i < len; i++) { ch = s.charAt(i) - numASCIICtrlChars; int bitmask = ch & 0x1f; int bitVectorIdx = ch >> 5; ch = arr[bitVectorIdx] & bitmask; if (ch == 1) { return false; } arr[bitVectorIdx] |= bitmask; } return true; }  }
PracticeQuestionsCh1 { public static boolean isUnique(String s) { int[] arr = new int[3]; int len = s.length(); int ch = -1; final int numASCIICtrlChars = 32; for (int i = 0; i < len; i++) { ch = s.charAt(i) - numASCIICtrlChars; int bitmask = ch & 0x1f; int bitVectorIdx = ch >> 5; ch = arr[bitVectorIdx] & bitmask; if (ch == 1) { return false; } arr[bitVectorIdx] |= bitmask; } return true; }  static boolean isUnique(String s); static boolean isPermutation(String s1, String s2); static String encodeRepeatedChars(final String str); static void fillIfZero(int[][] matrix); static boolean isRotation(String s1, String s2); }
PracticeQuestionsCh1 { public static boolean isUnique(String s) { int[] arr = new int[3]; int len = s.length(); int ch = -1; final int numASCIICtrlChars = 32; for (int i = 0; i < len; i++) { ch = s.charAt(i) - numASCIICtrlChars; int bitmask = ch & 0x1f; int bitVectorIdx = ch >> 5; ch = arr[bitVectorIdx] & bitmask; if (ch == 1) { return false; } arr[bitVectorIdx] |= bitmask; } return true; }  static boolean isUnique(String s); static boolean isPermutation(String s1, String s2); static String encodeRepeatedChars(final String str); static void fillIfZero(int[][] matrix); static boolean isRotation(String s1, String s2); static final Logger LOGGER; }