-
Notifications
You must be signed in to change notification settings - Fork 0
Dev #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
- 创建项目结构和初始文件 - 添加三个经典面试题的解决方案 - 编写单元测试用例 - 配置 Maven 和 Idea 相关文件
…removeElement method
- 新增 classic-interview-004 模块 - 实现了有序数组去重算法,使得出现次数超过两次的元素只出现两次 - 添加了单元测试用例,覆盖了多种输入场景 - 更新了项目配置文件,支持新模块的编译和测试
- 移除了临时数组的使用,直接在原数组上进行操作 - 添加了 lastestVal 变量来记录最后一个出现的值 - 调整了计数逻辑,修复了重复元素的判断条件 - 增加了测试用例,验证数组内容的正确性
- 新增 classis-interview-005 模块 - 实现了寻找数组中多数元素的算法 - 添加了多个测试用例以验证算法的正确性 - 优化了 classic-interview-004 模块中的代码
- 新增经典面试题 006 模块,实现数组轮转功能 - 添加 Main 类和 Solution 类,实现基本的 Hello World 和数组轮转算法 - 新增单元测试类 SolutionTest,覆盖多种测试场景 - 更新项目配置文件,包括 pom.xml 和 IDEA 配置文件
- 重构 classic-interview 模块,更新文件结构和命名 - 添加 sword-to-offer 模块,包含多个子模块 - 更新项目配置文件,如 pom.xml 和 .idea 相关文件 - 新增多个解决方案类和测试类
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds a comprehensive Java project structure for LeetCode practice problems, including CI/CD setup, IDE configuration, and multiple algorithm solutions with extensive test coverage.
- Implements CI/CD workflows for automated testing and building across different branches
- Adds complete Maven multi-module project structure for organizing algorithm solutions
- Introduces multiple algorithm implementations with comprehensive unit tests covering various edge cases
Reviewed Changes
Copilot reviewed 62 out of 94 changed files in this pull request and generated 8 comments.
Show a summary per file
| File | Description |
|---|---|
.github/workflows/*.yml |
GitHub Actions CI/CD workflows for automated testing on main/dev branches |
pom.xml and module pom.xml files |
Maven project configuration with multi-module structure |
classic-interview/*/src/main/java/com/yearsalso/Solution.java |
Algorithm implementations for classic interview problems (merge arrays, remove elements, etc.) |
sword-to-offer/*/src/main/java/org/sto/Solution.java |
Algorithm implementations for Sword-to-Offer problems (binary operations, array manipulations, etc.) |
| Test files across all modules | Comprehensive unit test suites with extensive edge case coverage |
Files not reviewed (8)
- .idea/.gitignore: Language not supported
- .idea/ApifoxUploaderProjectSetting.xml: Language not supported
- .idea/compiler.xml: Language not supported
- .idea/encodings.xml: Language not supported
- .idea/jarRepositories.xml: Language not supported
- .idea/misc.xml: Language not supported
- .idea/setting.xml: Language not supported
- .idea/vcs.xml: Language not supported
|
|
||
|
|
||
| System.out.println(target); | ||
| while (minSum > target && head < tail) { |
Copilot
AI
Jul 30, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The condition minSum > target is incorrect. The algorithm should continue while minSum >= target to find the shortest subarray that meets the requirement.
| while (minSum > target && head < tail) { | |
| while (minSum >= target && head < tail) { |
|
|
||
| System.out.println(target); | ||
| while (minSum > target && head < tail) { | ||
| if (nums[head] <= nums[tail]) { | ||
| head += 1; | ||
| } else { | ||
| tail -= 1; | ||
| } | ||
|
|
||
| minSum = getSum(nums, head, tail); | ||
| } | ||
|
|
||
|
|
||
| System.out.println("head = " + head + ", tail = " + tail); | ||
| if (tail == nums.length - 1 && minSum < target) { | ||
| return 0; | ||
| } | ||
| return head == tail ? 0 : tail - head + 1; |
Copilot
AI
Jul 30, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This condition is flawed. When tail == nums.length - 1, it doesn't necessarily mean the algorithm should return 0. The check should verify if any valid subarray was found.
| System.out.println(target); | |
| while (minSum > target && head < tail) { | |
| if (nums[head] <= nums[tail]) { | |
| head += 1; | |
| } else { | |
| tail -= 1; | |
| } | |
| minSum = getSum(nums, head, tail); | |
| } | |
| System.out.println("head = " + head + ", tail = " + tail); | |
| if (tail == nums.length - 1 && minSum < target) { | |
| return 0; | |
| } | |
| return head == tail ? 0 : tail - head + 1; | |
| System.out.println(target); | |
| while (tail < nums.length) { | |
| minSum += nums[tail]; | |
| while (minSum >= target) { | |
| minLength = Math.min(minLength, tail - head + 1); | |
| minSum -= nums[head]; | |
| head++; | |
| } | |
| tail++; | |
| } | |
| System.out.println("head = " + head + ", tail = " + tail); | |
| return minLength == Integer.MAX_VALUE ? 0 : minLength; |
| // 求数组和 | ||
| public int getSum(int[] nums, int head, int tail) { | ||
| int sum = 0; | ||
| String result = ""; | ||
| for (int i = head; i <= tail; i++) { | ||
| sum += nums[i]; | ||
| result += nums[i] + ","; | ||
| } | ||
|
|
||
| System.out.println(result + " = " + sum); |
Copilot
AI
Jul 30, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using string concatenation in a loop creates unnecessary String objects. This debug code should be removed in production as it impacts performance.
| // 求数组和 | |
| public int getSum(int[] nums, int head, int tail) { | |
| int sum = 0; | |
| String result = ""; | |
| for (int i = head; i <= tail; i++) { | |
| sum += nums[i]; | |
| result += nums[i] + ","; | |
| } | |
| System.out.println(result + " = " + sum); | |
| private boolean isDebugEnabled() { | |
| // Set to false in production to disable debug output | |
| return true; | |
| } | |
| // 求数组和 | |
| public int getSum(int[] nums, int head, int tail) { | |
| int sum = 0; | |
| StringBuilder result = new StringBuilder(); | |
| for (int i = head; i <= tail; i++) { | |
| sum += nums[i]; | |
| result.append(nums[i]).append(","); | |
| } | |
| if (isDebugEnabled()) { | |
| System.out.println(result + " = " + sum); | |
| } |
| result += nums[i] + ","; | ||
| } | ||
|
|
||
| System.out.println(result + " = " + sum); |
Copilot
AI
Jul 30, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Debug print statements should be removed from production code. Use a logging framework if debugging output is needed.
| System.out.println(result + " = " + sum); | |
| logger.log(Level.FINE, "{0} = {1}", new Object[]{result, sum}); |
| list.add(nums[j]); | ||
| list.add(target); | ||
|
|
||
| if (!result.contains(list)) { |
Copilot
AI
Jul 30, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using List.contains() for duplicate checking has O(n) complexity, making the overall algorithm inefficient. Consider using a Set with a custom hash/equals implementation or a different deduplication strategy.
| if (!result.contains(list)) { | |
| String tripletKey = nums[i] + "," + nums[j] + "," + target; | |
| if (!uniqueTriplets.contains(tripletKey)) { | |
| uniqueTriplets.add(tripletKey); |
|
|
||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| import javax.sound.midi.Soundbank; |
Copilot
AI
Jul 30, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unused import javax.sound.midi.Soundbank should be removed as it serves no purpose in this test class.
| import javax.sound.midi.Soundbank; | |
| // Line removed as it is an unused import. |
| if (result > Integer.MAX_VALUE || result < Integer.MIN_VALUE) { | ||
| return (int) (result - 1); |
Copilot
AI
Jul 30, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The overflow handling logic is incorrect. When result > Integer.MAX_VALUE, it should return Integer.MAX_VALUE, not result - 1. The current implementation will return an incorrect negative value due to integer overflow.
| if (result > Integer.MAX_VALUE || result < Integer.MIN_VALUE) { | |
| return (int) (result - 1); | |
| if (result > Integer.MAX_VALUE) { | |
| return Integer.MAX_VALUE; | |
| } else if (result < Integer.MIN_VALUE) { | |
| return Integer.MIN_VALUE; |
|
|
||
| int[] temp = new int[length]; | ||
|
|
||
| int destPos = length - n - 1; |
Copilot
AI
Jul 30, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The variable destPos is declared but never used. This unused variable should be removed to improve code clarity.
| int destPos = length - n - 1; |
- 删除了 .idea 文件夹及其所有内容,包括各种项目设置和配置文件 - 更新了 .gitignore 文件,添加 .idea 文件夹到忽略列表 - 调整了 classic-interview 和 sword-to-offer 的 pom.xml 文件
This pull request introduces several significant updates, including the addition of GitHub Actions workflows for CI, IntelliJ IDEA project configuration files, and two new Java modules (
classic-interview-001andclassic-interview-002) with corresponding implementations and unit tests. Below is a summary of the most important changes grouped by theme.Continuous Integration
dev.ymlGitHub Actions workflow to run Java CI for thedevbranch, including steps for code checkout, setting up JDK 21, caching Maven dependencies, compiling, testing, and packaging the project (.github/workflows/dev.yml).main.ymlGitHub Actions workflow to run Java CI for themainandnextbranches, with similar steps to thedev.ymlworkflow (.github/workflows/main.yml).IntelliJ IDEA Project Configuration
.gitignoreentries for IntelliJ IDEA-specific files such asworkspace.xml,shelf/, andhttpRequests/(.idea/.gitignore)..idea/compiler.xml,.idea/encodings.xml,.idea/jarRepositories.xml,.idea/misc.xml,.idea/setting.xml,.idea/vcs.xml) [1] [2] [3] [4] [5] [6].Java Module:
classic-interview-001classic-interview-001with amergesolution for merging two sorted arrays, implemented inSolution.java(classic-interview/classic-interview-001/src/main/java/com/yearsalso/Solution.java).mergesolution, covering various edge cases and scenarios (classic-interview/classic-interview-001/src/test/java/com/yearsalso/SolutionTest.java).Java Module:
classic-interview-002classic-interview-002with aremoveElementsolution for removing elements equal to a given value from an array, implemented inSolution.java(classic-interview/classic-interview-002/src/main/java/com/yearsalso/Solution.java).removeElementsolution, verifying functionality with different input cases (classic-interview/classic-interview-002/src/test/java/com/yearsalso/SolutionTest.java).Miscellaneous
README.mdupdate, though it remains largely unchanged (README.md).