Skip to content

Commit b8e52ad

Browse files
committed
update
1 parent abf7df1 commit b8e52ad

File tree

2 files changed

+48
-1
lines changed

2 files changed

+48
-1
lines changed

leetcode_java/src/main/java/LeetCodeJava/HashTable/SubarraySumEqualsK.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ public int subarraySum(int[] nums, int k) {
8989
*
9090
*
9191
* Purpose of map.put(0, 1);
92-
*
92+
*
9393
* 1. Handle the Initial Case:
9494
* • The prefix sum presum starts at 0 before any elements of the array are processed.
9595
* • 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.
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package dev;
2+
3+
public class copilotTest1 {
4+
public static void main(String[] args) {
5+
// offer a for loop from 1 to 10
6+
for (int i = 1; i <= 10; i++) {
7+
// print the value of i
8+
System.out.println(i);
9+
}
10+
11+
// offer a for loop from 10 to 1
12+
for (int i = 10; i >= 1; i--) {
13+
// print the value of i
14+
System.out.println(i);
15+
}
16+
17+
// offer a for loop from 1 to 10
18+
for (int i = 1; i <= 10; i++) {
19+
// print the value of i
20+
System.out.println(i);
21+
}
22+
23+
// offer a for loop from -1 to -10
24+
for (int i = -1; i >= -10; i--) {
25+
// print the value of i
26+
System.out.println(i);
27+
}
28+
29+
// offer a binrary search implementation
30+
int[] arr = {1, 2, 3, 4, 5, 6, 7, 8, 9};
31+
int target = 5;
32+
int left = 0;
33+
int right = arr.length - 1;
34+
while (left <= right) {
35+
int mid = left + (right - left) / 2;
36+
if (arr[mid] == target) {
37+
System.out.println("Found at index " + mid);
38+
break;
39+
} else if (arr[mid] < target) {
40+
left = mid + 1;
41+
} else {
42+
right = mid - 1;
43+
}
44+
}
45+
46+
}
47+
}

0 commit comments

Comments
 (0)