refactor: remove Java code sections from all LeetCode Hot 100 markdown files
- Remove all "## Java 解法" sections and Java code blocks - Replace "## Go 解法" with "## 解法" - Remove "### Go 代码要点" and "### Java 代码要点" sections - Keep all Go code sections intact - Maintain complete documentation structure and content - Update 22 markdown files in the LeetCode Hot 100 directory
This commit is contained in:
@@ -116,56 +116,6 @@ func main() {
|
||||
|
||||
### Java 实现(回溯法)
|
||||
|
||||
```java
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class Subsets {
|
||||
|
||||
public List<List<Integer>> subsets(int[] nums) {
|
||||
List<List<Integer>> result = new ArrayList<>();
|
||||
List<Integer> current = new ArrayList<>();
|
||||
backtrack(result, current, nums, 0);
|
||||
return result;
|
||||
}
|
||||
|
||||
private void backtrack(List<List<Integer>> result, List<Integer> current,
|
||||
int[] nums, int start) {
|
||||
// 将当前子集加入结果
|
||||
result.add(new ArrayList<>(current));
|
||||
|
||||
// 从 start 开始尝试包含每个元素
|
||||
for (int i = start; i < nums.length; i++) {
|
||||
// 选择当前元素
|
||||
current.add(nums[i]);
|
||||
// 递归处理下一个元素
|
||||
backtrack(result, current, nums, i + 1);
|
||||
// 撤销选择(回溯)
|
||||
current.remove(current.size() - 1);
|
||||
}
|
||||
}
|
||||
|
||||
// 测试用例
|
||||
public static void main(String[] args) {
|
||||
Subsets solution = new Subsets();
|
||||
|
||||
// 测试用例1
|
||||
int[] nums1 = {1, 2, 3};
|
||||
System.out.println("输入: [1, 2, 3]");
|
||||
System.out.println("输出: " + solution.subsets(nums1));
|
||||
|
||||
// 测试用例2
|
||||
int[] nums2 = {0};
|
||||
System.out.println("\n输入: [0]");
|
||||
System.out.println("输出: " + solution.subsets(nums2));
|
||||
|
||||
// 测试用例3
|
||||
int[] nums3 = {1, 2};
|
||||
System.out.println("\n输入: [1, 2]");
|
||||
System.out.println("输出: " + solution.subsets(nums3));
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### Go 实现(迭代法-位掩码)
|
||||
|
||||
@@ -192,26 +142,6 @@ func subsetsBitMask(nums []int) [][]int {
|
||||
|
||||
### Java 实现(迭代法-位掩码)
|
||||
|
||||
```java
|
||||
public List<List<Integer>> subsetsBitMask(int[] nums) {
|
||||
int n = nums.length;
|
||||
int total = 1 << n; // 2^n 个子集
|
||||
List<List<Integer>> result = new ArrayList<>();
|
||||
|
||||
for (int mask = 0; mask < total; mask++) {
|
||||
List<Integer> subset = new ArrayList<>();
|
||||
for (int i = 0; i < n; i++) {
|
||||
// 检查第 i 位是否为 1
|
||||
if ((mask & (1 << i)) != 0) {
|
||||
subset.add(nums[i]);
|
||||
}
|
||||
}
|
||||
result.add(subset);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
```
|
||||
|
||||
### Go 实现(级联法)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user