Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
yennanliu committed Dec 20, 2024
1 parent abf7df1 commit b8e52ad
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public int subarraySum(int[] nums, int k) {
*
*
* Purpose of map.put(0, 1);
*
*
* 1. Handle the Initial Case:
* • The prefix sum presum starts at 0 before any elements of the array are processed.
* • Adding map.put(0, 1) ensures that if a subarray’s prefix sum equals k (e.g., the subarray itself equals k ), it is counted correctly.
Expand Down
47 changes: 47 additions & 0 deletions leetcode_java/src/main/java/dev/copilotTest1.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package dev;

public class copilotTest1 {
public static void main(String[] args) {
// offer a for loop from 1 to 10
for (int i = 1; i <= 10; i++) {
// print the value of i
System.out.println(i);
}

// offer a for loop from 10 to 1
for (int i = 10; i >= 1; i--) {
// print the value of i
System.out.println(i);
}

// offer a for loop from 1 to 10
for (int i = 1; i <= 10; i++) {
// print the value of i
System.out.println(i);
}

// offer a for loop from -1 to -10
for (int i = -1; i >= -10; i--) {
// print the value of i
System.out.println(i);
}

// offer a binrary search implementation
int[] arr = {1, 2, 3, 4, 5, 6, 7, 8, 9};
int target = 5;
int left = 0;
int right = arr.length - 1;
while (left <= right) {
int mid = left + (right - left) / 2;
if (arr[mid] == target) {
System.out.println("Found at index " + mid);
break;
} else if (arr[mid] < target) {
left = mid + 1;
} else {
right = mid - 1;
}
}

}
}

0 comments on commit b8e52ad

Please sign in to comment.