Skip to content

Commit 9ecec2d

Browse files
JavaScalaDeveloperJavaScalaDeveloper
authored andcommitted
import
1 parent 65e264f commit 9ecec2d

File tree

44 files changed

+371
-252
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+371
-252
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package change.datastructure;
2+
3+
/**
4+
* 这个实体类包含了二叉树节点的value、左子节点、右子节点和指向父节点的指针。可以根据需求进行修改和扩展。
5+
*
6+
* 需要注意的是,在构造函数中,我们默认将左子节点、右子节点和父节点初始化为null,因为有些二叉树节点并不一定拥有左右子节点和父节点,这样当节点不存在时,这些变量就能够保证为null。
7+
*/
8+
9+
public class TreeNextLinkNode extends TreeNode{
10+
//指向父亲结点的指针
11+
public TreeNextLinkNode next;
12+
13+
public TreeNextLinkNode(int val, TreeNode left, TreeNode right, TreeNextLinkNode next) {
14+
super(val, left, right);
15+
this.next = next;
16+
}
17+
18+
public TreeNextLinkNode(int val, TreeNextLinkNode next) {
19+
super(val);
20+
this.next = next;
21+
}
22+
23+
public TreeNextLinkNode(TreeNextLinkNode next) {
24+
this.next = next;
25+
}
26+
public TreeNextLinkNode() {
27+
}
28+
29+
public TreeNextLinkNode getNext() {
30+
return next;
31+
}
32+
33+
public void setNext(TreeNextLinkNode next) {
34+
this.next = next;
35+
}
36+
}

change/datastructure/TreeLinkNode.java renamed to change/datastructure/TreeParentLinkNode.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,23 @@
66
* 需要注意的是,在构造函数中,我们默认将左子节点、右子节点和父节点初始化为null,因为有些二叉树节点并不一定拥有左右子节点和父节点,这样当节点不存在时,这些变量就能够保证为null。
77
*/
88
//@Data
9-
public class TreeLinkNode extends TreeNode{
9+
public class TreeParentLinkNode extends TreeNode{
1010
//指向父亲结点的指针
11-
public TreeLinkNode parent = null;
11+
public TreeParentLinkNode parent = null;
1212

13-
public TreeLinkNode() {
13+
public TreeParentLinkNode() {
1414
}
1515

16-
public TreeLinkNode(int val) {
16+
public TreeParentLinkNode(int val) {
1717
this.val = val;
1818
}
1919

20-
public TreeLinkNode(int val, TreeNode left, TreeNode right, TreeLinkNode parent) {
20+
public TreeParentLinkNode(int val, TreeNode left, TreeNode right, TreeParentLinkNode parent) {
2121
super(val, left, right);
2222
this.parent = parent;
2323
}
2424

25-
public TreeLinkNode(int val, TreeLinkNode left, TreeLinkNode right, TreeLinkNode parent) {
25+
public TreeParentLinkNode(int val, TreeParentLinkNode left, TreeParentLinkNode right, TreeParentLinkNode parent) {
2626
this.val = val;
2727
this.left = left;
2828
this.right = right;

change/scripts/Main.java

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,36 @@
11
package change.scripts;
22

3-
import java.io.IOException;
3+
import change.datastructure.ListNode;
4+
import change.tools.listnode.ListNodeUtils;
45

5-
import java.nio.file.Files;
6-
import java.nio.file.Paths;
7-
import java.util.regex.Matcher;
8-
import java.util.regex.Pattern;
96

107
public class Main {
118
public static void main(String[] args) {
12-
String filePath = "D:\\WorkSpaces\\leetcode-all\\solution\\0000-0099\\0001.Two Sum\\README.md";
13-
String str = null;
14-
try {
15-
str = new String(Files.readAllBytes(Paths.get(filePath)));
16-
} catch (IOException e) {
17-
e.printStackTrace();
18-
}
19-
9+
// 1,2,3,4 -> 2,1,4,3
10+
ListNode listNode = new ListNode(1, new ListNode(2, new ListNode(3, new ListNode(4))));
11+
ListNode res = reverse(listNode);
12+
System.out.println(ListNodeUtils.getValues(res));
13+
}
2014

21-
// String str = "caergblkmghfaersnecsblixetwey";
22-
Pattern pattern = Pattern.compile("");
23-
Matcher matcher = pattern.matcher(str);
24-
if (matcher.find()) {
25-
int startIndex = matcher.start();
26-
int endIndex = matcher.end();
27-
String result = str.substring(0, startIndex) + str.substring(endIndex);
28-
System.out.println(result);
29-
} else {
30-
System.out.println(str);
15+
private static ListNode reverse(ListNode listNode) {
16+
ListNode cur=listNode; //234
17+
boolean flag=false;
18+
int val=0;
19+
while (cur.next != null) {
20+
if (!flag) {
21+
cur.val= cur.next.val;
22+
val = cur.val;
23+
} else {
24+
cur.val=val;
25+
}
26+
cur=cur.next;
27+
// ListNode next = cur.next;
28+
// cur.next=pre;
29+
// pre=cur;
30+
// cur=next;
3131
}
32+
return cur;
33+
}
3234

3335

34-
}
3536
}

change/scripts/MergeMdFiles.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package change.scripts;
22

33
import java.io.*;
4+
import java.nio.file.Files;
5+
import java.nio.file.attribute.BasicFileAttributes;
46

57
public class MergeMdFiles {
68

@@ -21,10 +23,12 @@ public static void main(String[] args) throws IOException {
2123

2224
private static void mergeMdFiles(File dir, OutputStream os) throws IOException {
2325
File[] files = dir.listFiles();
26+
assert files != null;
2427
for (File file : files) {
25-
if (file.isDirectory()) {
28+
BasicFileAttributes basicFileAttributes = Files.readAttributes(file.toPath(), BasicFileAttributes.class);
29+
if (basicFileAttributes.isDirectory()) {
2630
mergeMdFiles(file, os);
27-
} else if (file.isFile() && file.getName().endsWith(".md")) {
31+
} else if (basicFileAttributes.isRegularFile() && file.getName().endsWith(".md")) {
2832
// 忽略solution根目录的文件
2933
if (file.getPath().length() > 60) {
3034
// String num = file.getPath().substring(46, 50);

change/scripts/MergeMdFilesByLevel.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
public class MergeMdFilesByLevel {
1111
// 前1500道
12-
private static final int MAX_NUM = 1500;
12+
private static final int MAX_NUM = 3000;
1313
private static final String OUTPUT_PATH = "D:\\WorkSpaces\\leetcode-all\\change\\scripts\\out\\"; // 修改为输出文件路径
1414
//题号->难度
1515
private static final Map<String, String> num2LevelMap = ParseMenu.getLineData().stream()
@@ -25,8 +25,8 @@ public static void main(String[] args) throws IOException {
2525
}
2626
Map<String, FileOutputStream> fileOutputStreamsMap = new HashMap<>();
2727
// 中等, 困难, 简单
28-
fileOutputStreamsMap.put("简单", new FileOutputStream(OUTPUT_PATH + "easy-0~" + MAX_NUM + "-v2023.md"));
29-
fileOutputStreamsMap.put("中等", new FileOutputStream(OUTPUT_PATH + "medium-0~" + MAX_NUM + "-v2023.md"));
28+
// fileOutputStreamsMap.put("简单", new FileOutputStream(OUTPUT_PATH + "easy-0~" + MAX_NUM + "-v2023.md"));
29+
// fileOutputStreamsMap.put("中等", new FileOutputStream(OUTPUT_PATH + "medium-0~" + MAX_NUM + "-v2023.md"));
3030
fileOutputStreamsMap.put("困难", new FileOutputStream(OUTPUT_PATH + "hard-0~" + MAX_NUM + "-v2023.md"));
3131

3232
mergeMdFiles(dir, fileOutputStreamsMap);

change/scripts/ParseMenu.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package change.scripts;
22

33
import java.io.BufferedReader;
4-
import java.io.FileInputStream;
54
import java.io.IOException;
65
import java.io.InputStreamReader;
76
import java.nio.file.Files;
-6.5 MB
Binary file not shown.
-36.6 MB
Binary file not shown.
-19.9 MB
Binary file not shown.

solution/0100-0199/0100.Same Tree/Solution.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,17 @@
1515
*/
1616
package com.solution._0100;
1717
import change.datastructure.*;
18+
import change.tools.listnode.TreeNodeUtils;
19+
1820
import java.util.*;
1921
public class Solution {
2022
public static void main(String[] args) {
21-
23+
TreeNode treeNode1 = TreeNodeUtils.buildTree();
24+
TreeNode treeNode2 = TreeNodeUtils.buildTree();
25+
boolean res = isSameTree(treeNode1, treeNode2);
26+
System.out.println(res);
2227
}
23-
public boolean isSameTree(TreeNode p, TreeNode q) {
28+
public static boolean isSameTree(TreeNode p, TreeNode q) {
2429
if (p == q) return true;
2530
if (p == null || q == null || p.val != q.val) return false;
2631
return isSameTree(p.left, q.left) && isSameTree(p.right, q.right);

0 commit comments

Comments
 (0)