public static int binarySearch(int[] nums, int target) { int start = 0, end = nums.length - 1; while (start <= end) { int mid = (start + end) / 2; if (nums[mid] == target) { if (mid < end && nums[mid] == nums[mid + 1]) { start = mid + 1; } else if (mid > start && nums[mid] == nums[mid - 1]) { end = mid - 1; } else { return mid; } } else if (nums[mid] < target) { start = mid + 1; } else { end = mid - 1; } } return -1; } public static void subStr(String s) { Set<String> stringSet = new HashSet<String>(); for (int i = 0; i < s.length(); i++) { for (int j = i + 1; j <= s.length(); j++) { String tstr = s.substring(i, j); if (stringSet.contains(tstr)) { System.out.print(tstr + " "); } stringSet.add(tstr); } } }