Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sum of square number #18

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions Searching/Find Smallest Letter Greater Than Target.java
Original file line number Diff line number Diff line change
@@ -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];
}
}
37 changes: 37 additions & 0 deletions Searching/Search in Rotated Sorted Array.java
Original file line number Diff line number Diff line change
@@ -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;
}
}
16 changes: 16 additions & 0 deletions Searching/Sum of Square Numbers.java
Original file line number Diff line number Diff line change
@@ -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;
}
}