diff --git a/Searching/Find Smallest Letter Greater Than Target.java b/Searching/Find Smallest Letter Greater Than Target.java new file mode 100644 index 0000000..e808aa8 --- /dev/null +++ b/Searching/Find Smallest Letter Greater Than Target.java @@ -0,0 +1,21 @@ +class Solution +{ +public char nextGreatestLetter(char[] letters, char target) + { + int start = 0, end = letters.length - 1; + + while (start <= end) + { + int mid = start + (end - start) / 2; + if (target < letters[mid]) + { + end = mid - 1; + } + else + { + start = mid + 1; + } + } + return letters[start % letters.length]; + } +} \ No newline at end of file diff --git a/Searching/Search in Rotated Sorted Array.java b/Searching/Search in Rotated Sorted Array.java new file mode 100644 index 0000000..9620cc5 --- /dev/null +++ b/Searching/Search in Rotated Sorted Array.java @@ -0,0 +1,37 @@ +class Solution +{ +public int search(int[] nums, int target) + { + int left = 0, right = nums.length - 1, mid; + while (left <= right) + { + mid = left + (right - left) / 2; + if (nums[mid] == target) + return mid; + // condition for left side is sort + if (nums[left] <= nums[mid]) + { + if (target >= nums[left] && target <= nums[mid]) + { + right = mid - 1; + } + else + { + left = mid + 1; + } + } + else + { + if (target >= nums[mid] && target <= nums[right]) + { + left = mid + 1; + } + else + { + right = mid - 1; + } + } + } + return -1; + } +} \ No newline at end of file diff --git a/Searching/Sum of Square Numbers.java b/Searching/Sum of Square Numbers.java new file mode 100644 index 0000000..5a9cdb6 --- /dev/null +++ b/Searching/Sum of Square Numbers.java @@ -0,0 +1,16 @@ +class Solution { + public boolean judgeSquareSum(int c) { + for (int i = 2; i * i <= c; i++) { + int count = 0; + if (c % i == 0) { + while (c % i == 0) { + count++; + c /= i; + } + if (i % 4 == 3 and count % 2 != 0) + return false; + } + } + return c % 4 != 3; + } +} \ No newline at end of file