From ec48e68eb1eedef6fbc5863d6eb834eacf7ed6ad Mon Sep 17 00:00:00 2001 From: dilip sahu Date: Sun, 23 Oct 2022 10:20:39 +0530 Subject: [PATCH 1/3] search in rotated sorted array.java --- Searching/Search in Rotated Sorted Array.java | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 Searching/Search in Rotated Sorted Array.java 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 From de1fc2c14dc9b67106f153033a37cdf5a3da0541 Mon Sep 17 00:00:00 2001 From: dilip sahu Date: Sun, 23 Oct 2022 10:27:02 +0530 Subject: [PATCH 2/3] Find Smallest Letter Greater Than Target.java --- ...d Smallest Letter Greater Than Target.java | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 Searching/Find Smallest Letter Greater Than Target.java 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 From 64101be4cb81935ff860fb7a7214118417cf12c8 Mon Sep 17 00:00:00 2001 From: dilip sahu Date: Sun, 23 Oct 2022 10:33:50 +0530 Subject: [PATCH 3/3] Sum of square number.java --- Searching/Sum of Square Numbers.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 Searching/Sum of Square Numbers.java 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