Skip to content

Commit f671c90

Browse files
代码重构 【Github Actions】
1 parent c79cac3 commit f671c90

File tree

94 files changed

+1609
-2111
lines changed

Some content is hidden

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

94 files changed

+1609
-2111
lines changed

README.md

Lines changed: 55 additions & 65 deletions
Large diffs are not rendered by default.

animation-simulation/Leetcode常用类和函数.md

Lines changed: 47 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Leetcode常用函数
1+
# Leetcode 常用函数
22

33
## 链表篇
44

@@ -7,22 +7,22 @@
77
### ListNode
88

99
```java
10-
ListNode list=new ListNode(0)
10+
ListNode list=new ListNode(0)
1111
```
1212

13-
初始化一个值为0的空节点,提倡的写法
13+
初始化一个值为 0 的空节点,提倡的写法
1414

1515
### HashSet
1616

17-
HashSet 基于 HashMap 来实现的,是一个不允许有重复元素的集合但是允许有null值,HashSet 是无序的,即不会记录插入的顺序。HashSet 不是线程安全的, 如果多个线程尝试同时修改 HashSet,则最终结果是不确定的。 您必须在多线程访问时显式同步对 HashSet 的并发访问。
17+
HashSet 基于 HashMap 来实现的,是一个不允许有重复元素的集合但是允许有 null 值,HashSet 是无序的,即不会记录插入的顺序。HashSet 不是线程安全的, 如果多个线程尝试同时修改 HashSet,则最终结果是不确定的。 您必须在多线程访问时显式同步对 HashSet 的并发访问。
1818

1919
```java
2020
HashSet<String> sites = new HashSet<String>();
2121
```
2222

2323
#### add()
2424

25-
往HashSet里添加元素
25+
往 HashSet 里添加元素
2626

2727
```
2828
sites.add("我是袁厨,大家快快关注我吧");
@@ -32,7 +32,7 @@ sites.add("我是袁厨,大家快快关注我吧");
3232

3333
#### remove()
3434

35-
remover()size()也是会用到的函数,具体用法和ArrayList一样
35+
remover()size()也是会用到的函数,具体用法和 ArrayList 一样
3636

3737
#### contains()
3838

@@ -44,13 +44,11 @@ System.out.println(sites.contains("我是袁厨,大家快快关注我吧"));
4444

4545
> 输出:true;
4646
47-
48-
4947
## 数组篇
5048

5149
### length
5250

53-
该函数是用来得到数组长度的函数,这里需要注意的是length后面没有括号
51+
该函数是用来得到数组长度的函数,这里需要注意的是 length 后面没有括号
5452

5553
### sort()
5654

@@ -85,7 +83,7 @@ return array;
8583
8684
### Arrays.copyOfRange()
8785

88-
将一个原始的数组,从下标0开始复制,复制到上标2,生成一个新的数组
86+
将一个原始的数组,从下标 0 开始复制,复制到上标 2,生成一个新的数组
8987

9088
```
9189
int[] array = {1,2,3,4};
@@ -94,7 +92,7 @@ return ar;
9492
9593
```
9694

97-
> array2: 1 , 2 ;
95+
> array2: 1 , 2 ;
9896
9997
### System.arraycopy();
10098

@@ -125,11 +123,11 @@ length:想要复制的长度
125123
126124
### 逻辑运算符
127125

128-
#### x | 0
126+
#### x | 0
129127

130128
得到的仍然是他本身,
131129

132-
例:1001|0000=1001;或运算代表的是如果两位其中有一个1则返回1,否则为0
130+
例:1001|0000=1001;或运算代表的是如果两位其中有一个 1 则返回 1,否则为 0
133131

134132
```java
135133
public static void main(String[] args) {
@@ -142,9 +140,9 @@ public static void main(String[] args) {
142140
143141
#### x & 0
144142

145-
无论任何数都会输出0,这个也很好理解。
143+
无论任何数都会输出 0,这个也很好理解。
146144

147-
例:1001&0000=0000;两位都为1才能返回1
145+
例:1001&0000=0000;两位都为 1 才能返回 1
148146

149147
```
150148
public static void main(String[] args) {
@@ -157,9 +155,9 @@ public static void main(String[] args) {
157155
158156
#### x ^ 0
159157

160-
得到的还是他本身,这个也很好理解,异或的含义就是如果相同输出0,如果不同输出1
158+
得到的还是他本身,这个也很好理解,异或的含义就是如果相同输出 0,如果不同输出 1
161159

162-
例:0111^0000=0111第一位相同,其余位不同
160+
例:0111^0000=0111 第一位相同,其余位不同
163161

164162
```java
165163
public static void main(String[] args) {
@@ -172,7 +170,7 @@ public static void main(String[] args) {
172170
173171
#### x | 1
174172

175-
如果是奇数的话,还是它本身,偶数的话则加1
173+
如果是奇数的话,还是它本身,偶数的话则加 1
176174

177175
```java
178176
int x =-9 ;
@@ -185,7 +183,7 @@ System.out.println(y|1);
185183
186184
#### x ^ 1
187185

188-
如果是偶数则加1,如果是奇数则减1
186+
如果是偶数则加 1,如果是奇数则减 1
189187

190188
```java
191189
int x =-9 ;
@@ -198,7 +196,7 @@ System.out.println(y^1);
198196
199197
#### x & 1
200198

201-
得出最后一位是0还是1,通常会用来判断奇偶
199+
得出最后一位是 0 还是 1,通常会用来判断奇偶
202200

203201
```java
204202
int x =-9 ;
@@ -211,7 +209,7 @@ System.out.println(y&1);
211209
212210
#### 1<<3
213211

214-
代表的含义是将1左移3位,即0001 ---->1000则为2^3为8
212+
代表的含义是将 1 左移 3 位,即 0001 ---->1000 则为 2^3 为 8
215213

216214
```java
217215
System.out.println(1<<3);
@@ -221,36 +219,34 @@ System.out.println(1<<3);
221219
222220
#### HashMap
223221

224-
创建一个HashMap,两种数据类型
222+
创建一个 HashMap,两种数据类型
225223

226224
```
227225
HashMap<Integer,Integer> map = new HashMap<Integer,Integer>();
228226
```
229227

230-
往hashmap里面插入数据
228+
往 hashmap 里面插入数据
231229

232230
```java
233231
for (int num : arr){
234232
map.put(num, map.getOrDefault(num, 0) + 1);//如果没有则添加,如果有则加1
235-
}
233+
}
236234
```
237235

238-
遍历Hashmap,查询值为k的元素
236+
遍历 Hashmap,查询值为 k 的元素
239237

240238
```
241239
for (int k : hashmap.keySet())
242240
if (hashmap.get(k) == 1) return k;
243-
241+
244242
```
245243

246-
遍历 HashSet
244+
遍历 HashSet
247245

248246
```
249247
set.iterator().next();//迭代器
250248
```
251249

252-
253-
254250
## 树篇
255251

256252
### ArrayList<List<对象类型>>
@@ -274,14 +270,14 @@ ArrayList 类是一个可以动态修改的数组,与普通数组的区别就
274270
```java
275271
public class Test {
276272
public static void main(String[] args) {
277-
List<String> array = new ArrayList<>();
273+
List<String> array = new ArrayList<>();
278274
array.add("大家好我是袁厨");
279275
System.out.println(array);
280276
}
281277
}
282278
```
283279

284-
> 输出:大家好我是袁厨
280+
> 输出:大家好我是袁厨
285281
286282
#### get()
287283

@@ -290,15 +286,15 @@ get()函数用于获取动态数组的元素,括号内为索引值
290286
```java
291287
public class Test {
292288
public static void main(String[] args) {
293-
List<String> array = new ArrayList<>();
289+
List<String> array = new ArrayList<>();
294290
array.add("大家好我是袁厨");
295291
System.out.println(array.get(0));//获取第一个元素
296292
}
297293
}
298294

299295
```
300296

301-
> 输出:大家好我是袁厨
297+
> 输出:大家好我是袁厨
302298
303299
#### set()
304300

@@ -307,7 +303,7 @@ set()用于修改元素,括号内为索引值
307303
```
308304
public class Test {
309305
public static void main(String[] args) {
310-
List<String> array = new ArrayList<>();
306+
List<String> array = new ArrayList<>();
311307
array.add("大家好我是袁厨");
312308
array.set(0,"祝大家天天开心")
313309
System.out.println(array.get(0));//获取第一个元素
@@ -324,7 +320,7 @@ public class Test {
324320
```
325321
public class Test {
326322
public static void main(String[] args) {
327-
List<String> array = new ArrayList<>();
323+
List<String> array = new ArrayList<>();
328324
array.add("大家好我是袁厨");
329325
array.add("祝大家天天开心");
330326
array.remove(0);
@@ -337,7 +333,7 @@ public class Test {
337333
338334
#### isEmpty()
339335

340-
isEmpty()函数判断是否为空,这个函数用到的地方很多,队列和栈的时候总会用。总是会在while循环中使用
336+
isEmpty()函数判断是否为空,这个函数用到的地方很多,队列和栈的时候总会用。总是会在 while 循环中使用
341337

342338
while(!queue.isEmpty()){
343339

@@ -348,7 +344,7 @@ while(!queue.isEmpty()){
348344
```
349345
public class Test {
350346
public static void main(String[] args) {
351-
List<String> array = new ArrayList<>();
347+
List<String> array = new ArrayList<>();
352348
array.add("大家好我是袁厨");
353349
array.add("祝大家天天开心");
354350
array.remove(0);
@@ -411,14 +407,14 @@ public class Test{
411407
sBuffer.append("是");
412408
sBuffer.append("袁厨");
413409
sBuffer.append("大家点个关注吧");
414-
System.out.println(sBuffer);
410+
System.out.println(sBuffer);
415411
}
416412
}
417413
```
418414

419415
> 输出:我的名字是袁厨大家点个关注吧
420416
421-
String中的字符串是不允许修改的,这个StringBuffer可以进行修改,做字符串的题目时会经常用到,树的题目中也偶尔会遇到
417+
String 中的字符串是不允许修改的,这个 StringBuffer 可以进行修改,做字符串的题目时会经常用到,树的题目中也偶尔会遇到
422418

423419
### charAt(i)
424420

@@ -438,9 +434,9 @@ public class Test {
438434
439435
这个函数的用法,就跟我们根据数组的索引输出值一样。在字符串题目中也比较常用。
440436

441-
### s.charAt(index)-'0'
437+
### s.charAt(index)-'0'
442438

443-
这个函数的用途是将字符串索引值变成int型。知道这个可以大大提高刷题效率。大家可以掌握一下。
439+
这个函数的用途是将字符串索引值变成 int 型。知道这个可以大大提高刷题效率。大家可以掌握一下。
444440

445441
```java
446442
public class Test {
@@ -457,16 +453,16 @@ public class Test {
457453

458454
> 输出:java.lang.Integer
459455
460-
### Integer.toString()
456+
### Integer.toString()
461457

462-
该函数用于将int型变为string型,比如这个**第9题求回文数**的题目,我们就是先将x变为字符串,然后再遍历字符串
458+
该函数用于将 int 型变为 string 型,比如这个**第 9 题求回文数**的题目,我们就是先将 x 变为字符串,然后再遍历字符串
463459

464460
```java
465461
class Solution {
466462
public boolean isPalindrome(int x) {
467463
if(x<0){
468464
return false;
469-
}
465+
}
470466
//将int型变成string型,然后遍历字符串,不再需要使用额外数组进行存储
471467
String t = Integer.toString(x);
472468
int i = 0;
@@ -495,12 +491,12 @@ public String substring(int beginIndex);
495491
public String substring(int beginIndex, int endIndex);
496492
```
497493

498-
表示两种情况,一种是从beginIndex到结尾,一种是从beginIndex ->endIndex;
494+
表示两种情况,一种是从 beginIndex 到结尾,一种是从 beginIndex ->endIndex;
499495

500496
```
501497
String Str = new String("程序员爱做饭");
502498
System.out.println(Str.substring(3) );
503-
System.out.println(Str.substring(4, 5) );
499+
System.out.println(Str.substring(4, 5) );
504500
```
505501

506502
> 输出:爱做饭,做
@@ -515,8 +511,8 @@ public static void main(String args[]){
515511
Integer y = 10;
516512
Integer z =5;
517513
Short a = 5;
518-
System.out.println(x.equals(y));
519-
System.out.println(x.equals(z));
514+
System.out.println(x.equals(y));
515+
System.out.println(x.equals(z));
520516
System.out.println(x.equals(a));
521517
}
522518
```
@@ -533,14 +529,12 @@ System.out.println(s);
533529

534530
> 输出:12345
535531
536-
### char数组变为String
532+
### char 数组变为 String
537533

538534
```java
539535
String newstr = new String (arr2,start,end);
540536
```
541537

542-
543-
544538
### indexOf
545539

546540
- **int indexOf(String str):** 返回指定字符在字符串中第一次出现处的索引,如果此字符串中没有这样的字符,则返回 -1。
@@ -561,7 +555,7 @@ return s.indexOf("LLL");
561555
Stack<TreeNode> stack = new Stack<TreeNode>();//创建栈
562556
```
563557

564-
上面的是创建新栈,栈的变量类型为TreeNode,我们用深度优先遍历树来举例
558+
上面的是创建新栈,栈的变量类型为 TreeNode,我们用深度优先遍历树来举例
565559

566560
#### push()
567561

@@ -576,7 +570,7 @@ Stack<TreeNode> stack = new Stack<TreeNode>();//创建栈
576570
移除堆栈顶部的对象,并作为此函数的值返回该对象。
577571

578572
```java
579-
TreeNode temp = stack.pop();//将栈顶元素出栈,赋值TreeNode变量temp
573+
TreeNode temp = stack.pop();//将栈顶元素出栈,赋值TreeNode变量temp
580574
```
581575

582576
peek()
@@ -600,4 +594,3 @@ while(!stack.isEmpty()){
600594
//反转并变为字符串
601595
return str.reverse().toString();
602596
```
603-

0 commit comments

Comments
 (0)