From b8e52ad7500eecc9fd76642bc7f1eaec0e417617 Mon Sep 17 00:00:00 2001 From: yennanliu Date: Fri, 20 Dec 2024 10:46:58 +0800 Subject: [PATCH] update --- .../HashTable/SubarraySumEqualsK.java | 2 +- .../src/main/java/dev/copilotTest1.java | 47 +++++++++++++++++++ 2 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 leetcode_java/src/main/java/dev/copilotTest1.java diff --git a/leetcode_java/src/main/java/LeetCodeJava/HashTable/SubarraySumEqualsK.java b/leetcode_java/src/main/java/LeetCodeJava/HashTable/SubarraySumEqualsK.java index 8cedb47a..dceb8df2 100644 --- a/leetcode_java/src/main/java/LeetCodeJava/HashTable/SubarraySumEqualsK.java +++ b/leetcode_java/src/main/java/LeetCodeJava/HashTable/SubarraySumEqualsK.java @@ -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. diff --git a/leetcode_java/src/main/java/dev/copilotTest1.java b/leetcode_java/src/main/java/dev/copilotTest1.java new file mode 100644 index 00000000..aeeb7a99 --- /dev/null +++ b/leetcode_java/src/main/java/dev/copilotTest1.java @@ -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; + } + } + + } +}