Skip to content

Commit

Permalink
update 33 java, progress
Browse files Browse the repository at this point in the history
  • Loading branch information
yennanliu committed Feb 28, 2024
1 parent 83629cb commit 6a1e7c6
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 12 deletions.
2 changes: 1 addition & 1 deletion data/progress.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
20240228: 20,21
20240228: 20,21,23,33(again)
20240227: 1,3,5,4,19
20231218: 57(todo),58(todo),268,61(todo),297
20231211: 39,53,48,56
Expand Down
18 changes: 9 additions & 9 deletions data/to_review.txt
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
2024-04-23 -> ['20,21']
2024-04-23 -> ['20,21,23,33(again)']
2024-04-22 -> ['1,3,5,4,19']
2024-04-02 -> ['20,21']
2024-04-02 -> ['20,21,23,33(again)']
2024-04-01 -> ['1,3,5,4,19']
2024-03-20 -> ['20,21']
2024-03-20 -> ['20,21,23,33(again)']
2024-03-19 -> ['1,3,5,4,19']
2024-03-12 -> ['20,21']
2024-03-12 -> ['20,21,23,33(again)']
2024-03-11 -> ['1,3,5,4,19']
2024-03-07 -> ['20,21']
2024-03-07 -> ['20,21,23,33(again)']
2024-03-06 -> ['1,3,5,4,19']
2024-03-04 -> ['20,21']
2024-03-04 -> ['20,21,23,33(again)']
2024-03-03 -> ['1,3,5,4,19']
2024-03-02 -> ['20,21']
2024-03-01 -> ['20,21', '1,3,5,4,19']
2024-02-29 -> ['20,21', '1,3,5,4,19']
2024-03-02 -> ['20,21,23,33(again)']
2024-03-01 -> ['20,21,23,33(again)', '1,3,5,4,19']
2024-02-29 -> ['20,21,23,33(again)', '1,3,5,4,19']
2024-02-28 -> ['1,3,5,4,19']
2024-02-11 -> ['57(todo),58(todo),268,61(todo),297']
2024-02-04 -> ['39,53,48,56']
Expand Down
2 changes: 2 additions & 0 deletions doc/cheatsheet/binary_search.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@
- Garena/test1.py
- Search in Rotated Sorted Array
- LC 033
- // CASE 1) sub array left is sorted
- // CASE 2) sub array right is sorted
- Search in 2D array
- LC 74
- Find min in Rotation array
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@

public class SearchInRotatedSortedArray {

// V0
// IDEA : BINARY SEARCH
// CASE 1) sub array left is sorted
// CASE 2) sub array right is sorted
public int search(int[] nums, int target) {

if (nums.length == 0 || nums.equals(null)){
Expand Down Expand Up @@ -46,7 +50,7 @@ public int search(int[] nums, int target) {
* - target > nums[r] || target < nums[mid]
*
*/
// Case 2: subarray on mid's left is sorted
// Case 1: subarray on mid's left is sorted
/** NOTE !!! we compare mid with left, instead of 0 idx element */
else if (nums[mid] >= nums[l]) {
if (target >= nums[l] && target < nums[mid]) {
Expand All @@ -56,7 +60,7 @@ else if (nums[mid] >= nums[l]) {
}
}

// Case 3: subarray on mid's right is sorted
// Case 2: subarray on mid's right is sorted
else {
if (target <= nums[r] && target > nums[mid]) {
l = mid + 1;
Expand Down

0 comments on commit 6a1e7c6

Please sign in to comment.