Skip to content

Commit d780e3a

Browse files
Sorting and Binary Search Fixed
1 parent 9fa1591 commit d780e3a

16 files changed

Lines changed: 24 additions & 0 deletions
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import java.util.*;
2+
3+
class Solution {
4+
public int majorityElement(int[] nums) {
5+
Arrays.sort(nums);
6+
return nums[nums.length/2];
7+
}
8+
}

5 Sorting/problems/CountElements.java renamed to 1 Leetcode Easy Problems/Leetcode 2148 Count Elements With Strictly Smaller and Greater Elements .java

File renamed without changes.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import java.util.*;
2+
3+
class Solution {
4+
public boolean containsDuplicate(int[] nums) {
5+
// O(nlogn)
6+
Arrays.sort(nums);
7+
8+
// O(n)
9+
for (int i = 0; i < nums.length - 1; i++) {
10+
if (nums[i] == nums[i+1]) {
11+
return true;
12+
}
13+
}
14+
return false;
15+
}
16+
}
File renamed without changes.

6 Binary Search/problems/SearchInsertPosition.java renamed to 1 Leetcode Easy Problems/Leetcode 35 Search Insert Position using Binary Search.java

File renamed without changes.

6 Binary Search/problems/GuessNumberHigherOrLower.java renamed to 1 Leetcode Easy Problems/Leetcode 374 Guess Number Higher or Lower.java

File renamed without changes.
File renamed without changes.
File renamed without changes.

5 Sorting/problems/MergeSortedArray.java renamed to 1 Leetcode Easy Problems/Leetcode 88 Merge Sorted Array using Sorting.java

File renamed without changes.

5 Sorting/problems/SquaresOfSortedArray.java renamed to 1 Leetcode Easy Problems/Leetcode 977 Squares of a Sorted Array.java

File renamed without changes.

0 commit comments

Comments
 (0)