Skip to content

Commit

Permalink
✨style: Bulk processing format
Browse files Browse the repository at this point in the history
  • Loading branch information
SharingSource committed May 9, 2022
1 parent b073f5b commit 1fca173
Show file tree
Hide file tree
Showing 257 changed files with 572 additions and 614 deletions.
12 changes: 4 additions & 8 deletions LeetCode/1-10/1. 两数之和(简单).md
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,19 @@ Tag : 「哈希表」、「模拟」
你可以按任意顺序返回答案。

示例 1:

```
输入:nums = [2,7,11,15], target = 9
输出:[0,1]
解释:因为 nums[0] + nums[1] == 9 ,返回 [0, 1] 。
```

示例 2:

```
输入:nums = [3,2,4], target = 6
输出:[1,2]
```


示例 3:

```
输入:nums = [3,3], target = 6
输出:[0,1]
Expand All @@ -38,9 +34,9 @@ Tag : 「哈希表」、「模拟」

提示:

* 2 <= nums.length <= $10^3$
* -$10^9$ <= nums[i] <= $10^9$
* -$10^9$ <= target <= $10^9$
* $2 <= nums.length <= 10^3$
* -$10^9 <= nums[i] <= 10^9$
* -$10^9 <= target <= 10^9$
* 只会存在一个有效答案

---
Expand Down Expand Up @@ -137,7 +133,7 @@ class Solution {

### 最后

这是我们「刷穿 LeetCode」系列文章的第 `No.1` 篇,系列开始于 2021/01/01,截止于起始日 LeetCode 上共有 1916 道题目,部分是有锁题,我们将先将所有不带锁的题目刷完
这是我们「刷穿 LeetCode」系列文章的第 `No.1` 篇,系列开始于 2021/01/01,截止于起始日 LeetCode 上共有 1916 道题目,部分是有锁题,我们将先把所有不带锁的题目刷完

在这个系列文章里面,除了讲解解题思路以外,还会尽可能给出最为简洁的代码。如果涉及通解还会相应的代码模板。

Expand Down
2 changes: 1 addition & 1 deletion LeetCode/1-10/10. 正则表达式匹配(困难).md
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ class Solution {

### 最后

这是我们「刷穿 LeetCode」系列文章的第 `No.10` 篇,系列开始于 2021/01/01,截止于起始日 LeetCode 上共有 1916 道题目,部分是有锁题,我们将先将所有不带锁的题目刷完
这是我们「刷穿 LeetCode」系列文章的第 `No.10` 篇,系列开始于 2021/01/01,截止于起始日 LeetCode 上共有 1916 道题目,部分是有锁题,我们将先把所有不带锁的题目刷完

在这个系列文章里面,除了讲解解题思路以外,还会尽可能给出最为简洁的代码。如果涉及通解还会相应的代码模板。

Expand Down
4 changes: 2 additions & 2 deletions LeetCode/1-10/2. 两数相加(中等).md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ Tag : 「递归」、「链表」、「数学」、「模拟」
做有关链表的题目,有个常用技巧:添加一个虚拟头结点(哨兵),帮助简化边界情况的判断。

代码:
```Java []
```Java
class Solution {
public ListNode addTwoNumbers(ListNode l1, ListNode l2) {
ListNode dummy = new ListNode(0);
Expand Down Expand Up @@ -80,7 +80,7 @@ class Solution {

### 最后

这是我们「刷穿 LeetCode」系列文章的第 `No.2` 篇,系列开始于 2021/01/01,截止于起始日 LeetCode 上共有 1916 道题目,部分是有锁题,我们将先将所有不带锁的题目刷完
这是我们「刷穿 LeetCode」系列文章的第 `No.2` 篇,系列开始于 2021/01/01,截止于起始日 LeetCode 上共有 1916 道题目,部分是有锁题,我们将先把所有不带锁的题目刷完

在这个系列文章里面,除了讲解解题思路以外,还会尽可能给出最为简洁的代码。如果涉及通解还会相应的代码模板。

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ Tag : 「哈希表」、「双指针」、「滑动窗口」
此时更新 `start` 的位置(使其右移),直到不满足 `map.get(right) > 1` (代表 `[start,end]` 恢复满足无重复字符的条件)。同时使用 `[start,end]` 长度更新答案。

代码:
```Java []
```Java
class Solution {
public int lengthOfLongestSubstring(String s) {
Map<Character, Integer> map = new HashMap<>();
Expand All @@ -81,7 +81,7 @@ class Solution {

### 最后

这是我们「刷穿 LeetCode」系列文章的第 `No.3` 篇,系列开始于 2021/01/01,截止于起始日 LeetCode 上共有 1916 道题目,部分是有锁题,我们将先将所有不带锁的题目刷完
这是我们「刷穿 LeetCode」系列文章的第 `No.3` 篇,系列开始于 2021/01/01,截止于起始日 LeetCode 上共有 1916 道题目,部分是有锁题,我们将先把所有不带锁的题目刷完

在这个系列文章里面,除了讲解解题思路以外,还会尽可能给出最为简洁的代码。如果涉及通解还会相应的代码模板。

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ Tag : 「二分」、「分治」

这样做的目的是为了避免分情况讨论:合并后的数组长度是奇数还是偶数。

```Java []
```Java
class Solution {
public double findMedianSortedArrays(int[] nums1, int[] nums2) {
int n = nums1.length, m = nums2.length;
Expand Down Expand Up @@ -99,7 +99,7 @@ class Solution {

* 当 `nums1[si - 1] <= nums2[sj - 1]`:则表示第 `k` 小一定不在 `[i,si - 1]` 中,即在 `[si,n]` 或 `[j,m]` 中
```Java []
```Java
class Solution {
public double findMedianSortedArrays(int[] nums1, int[] nums2) {
int tot = nums1.length + nums2.length;
Expand Down Expand Up @@ -158,7 +158,7 @@ class Solution {

### 最后

这是我们「刷穿 LeetCode」系列文章的第 `No.4` 篇,系列开始于 2021/01/01,截止于起始日 LeetCode 上共有 1916 道题目,部分是有锁题,我们将先将所有不带锁的题目刷完
这是我们「刷穿 LeetCode」系列文章的第 `No.4` 篇,系列开始于 2021/01/01,截止于起始日 LeetCode 上共有 1916 道题目,部分是有锁题,我们将先把所有不带锁的题目刷完

在这个系列文章里面,除了讲解解题思路以外,还会尽可能给出最为简洁的代码。如果涉及通解还会相应的代码模板。

Expand Down
6 changes: 3 additions & 3 deletions LeetCode/1-10/5. 最长回文子串(中等).md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ Tag : 「模拟」、「回文串」
* 回文串长度是偶数,则依次判断 `s[i − k] == s[i + k − 1], k = 1,2,3…`

代码:
```Java []
```Java
class Solution {
public String longestPalindrome(String s) {
String ans = "";
Expand Down Expand Up @@ -108,7 +108,7 @@ Manacher 算法较长,为了避免回文串长度奇偶问题的分情况讨
*解释:"aba" 同样是符合题意的答案。*

代码:
```Java []
```Java
class Solution {
public String longestPalindrome(String s) {
if (s.length() == 1) return s;
Expand Down Expand Up @@ -171,7 +171,7 @@ class Solution {
---
### 最后

这是我们「刷穿 LeetCode」系列文章的第 `No.5` 篇,系列开始于 2021/01/01,截止于起始日 LeetCode 上共有 1916 道题目,部分是有锁题,我们将先将所有不带锁的题目刷完
这是我们「刷穿 LeetCode」系列文章的第 `No.5` 篇,系列开始于 2021/01/01,截止于起始日 LeetCode 上共有 1916 道题目,部分是有锁题,我们将先把所有不带锁的题目刷完

在这个系列文章里面,除了讲解解题思路以外,还会尽可能给出最为简洁的代码。如果涉及通解还会相应的代码模板。

Expand Down
6 changes: 3 additions & 3 deletions LeetCode/1-10/7. 整数反转(简单).md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ Tag : 「数学」、「模拟」
但由于数据范围过大,使用 int 会有溢出的风险,所以我们使用 long 来进行计算,在返回再转换为 int。

代码:
```Java []
```Java
class Solution {
public int reverse(int x) {
long ans = 0;
Expand Down Expand Up @@ -78,7 +78,7 @@ class Solution {
* 对于负数而言:溢出意味着 `ans * 10 + x % 10 < Integer.MIN_VALUE`,对等式进行变化后可得 `ans < (Integer.MIN_VALUE - x % 10) / 10)`。所以我们可以根据此变形公式进行预判断

代码:
```Java []
```Java
class Solution {
public int reverse(int x) {
int ans = 0;
Expand All @@ -100,7 +100,7 @@ class Solution {

### 最后

这是我们「刷穿 LeetCode」系列文章的第 `No.7` 篇,系列开始于 2021/01/01,截止于起始日 LeetCode 上共有 1916 道题目,部分是有锁题,我们将先将所有不带锁的题目刷完
这是我们「刷穿 LeetCode」系列文章的第 `No.7` 篇,系列开始于 2021/01/01,截止于起始日 LeetCode 上共有 1916 道题目,部分是有锁题,我们将先把所有不带锁的题目刷完

在这个系列文章里面,除了讲解解题思路以外,还会尽可能给出最为简洁的代码。如果涉及通解还会相应的代码模板。

Expand Down
4 changes: 2 additions & 2 deletions LeetCode/1-10/8. 字符串转换整数 (atoi)(中等).md
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ Tag : 「模拟」
确定逻辑之后,代码就好写了。

代码:
```Java []
```Java
class Solution {
public int myAtoi(String s) {
int n = s.length();
Expand Down Expand Up @@ -165,7 +165,7 @@ class Solution {

### 最后

这是我们「刷穿 LeetCode」系列文章的第 `No.8` 篇,系列开始于 2021/01/01,截止于起始日 LeetCode 上共有 1916 道题目,部分是有锁题,我们将先将所有不带锁的题目刷完
这是我们「刷穿 LeetCode」系列文章的第 `No.8` 篇,系列开始于 2021/01/01,截止于起始日 LeetCode 上共有 1916 道题目,部分是有锁题,我们将先把所有不带锁的题目刷完

在这个系列文章里面,除了讲解解题思路以外,还会尽可能给出最为简洁的代码。如果涉及通解还会相应的代码模板。

Expand Down
8 changes: 4 additions & 4 deletions LeetCode/1-10/9. 回文数(简单).md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ Tag : 「数学」、「回文串」
虽然进阶里提到了不能用字符串来解决,但还是提供一下吧。

代码:
```Java []
```Java
class Solution {
public boolean isPalindrome(int x) {
String s = String.valueOf(x);
Expand All @@ -67,7 +67,7 @@ class Solution {
原数值 `x` 的不超过 int 的表示范围,但翻转后的值会有溢出的风险,所以这里使用 `long` 进行接收,最后对比两者是否相等。

代码:
```Java []
```Java
class Solution {
public boolean isPalindrome(int x) {
if (x < 0) return false;
Expand Down Expand Up @@ -98,7 +98,7 @@ class Solution {
* 回文长度为偶数:回文中心在中间两个数中间,即 `前半部分 == 后半部分(翻转)`。如 123321

代码:
```Java []
```Java
class Solution {
public boolean isPalindrome(int x) {
// 对于 负数 和 x0、x00、x000 格式的数,直接返回 flase
Expand All @@ -120,7 +120,7 @@ class Solution {
---
### 最后

这是我们「刷穿 LeetCode」系列文章的第 `No.9` 篇,系列开始于 2021/01/01,截止于起始日 LeetCode 上共有 1916 道题目,部分是有锁题,我们将先将所有不带锁的题目刷完
这是我们「刷穿 LeetCode」系列文章的第 `No.9` 篇,系列开始于 2021/01/01,截止于起始日 LeetCode 上共有 1916 道题目,部分是有锁题,我们将先把所有不带锁的题目刷完

在这个系列文章里面,除了讲解解题思路以外,还会尽可能给出最为简洁的代码。如果涉及通解还会相应的代码模板。

Expand Down
10 changes: 5 additions & 5 deletions LeetCode/1001-1010/1006. 笨阶乘(中等).md
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ Tag : 「数学」、「栈」

代码:

```Java []
```Java
class Solution {
public int clumsy(int n) {
Deque<Integer> nums = new ArrayDeque<>();
Expand Down Expand Up @@ -127,7 +127,7 @@ class Solution {

通常我们需要先实现一个**可打表的算法(例如上述的解法一,这是为什么掌握「通用表达式」解法具有重要意义)**,将连续数字的答案打印输出,来找找规律:

```Java []
```Java
Solution solution = new Solution();
for (int i = 1; i <= 10000; i++) {
int res = solution.clumsy(i);
Expand All @@ -139,7 +139,7 @@ class Solution {

似乎 $n$ 与 答案比较接近,我们考虑将两者的差值输出:

```Java []
```Java
Solution solution = new Solution();
for (int i = 1; i <= 10000; i++) {
int res = solution.clumsy(i);
Expand All @@ -153,7 +153,7 @@ class Solution {

再修改我们的打表逻辑,来验证一下(只输出与我们猜想不一样的数字):

```Java []
```Java
Solution solution = new Solution();
int[] diff = new int[]{1,2,2,-1};
for (int i = 1; i <= 10000; i++) {
Expand Down Expand Up @@ -216,7 +216,7 @@ class Solution {

### 最后

这是我们「刷穿 LeetCode」系列文章的第 `No.1006` 篇,系列开始于 2021/01/01,截止于起始日 LeetCode 上共有 1916 道题目,部分是有锁题,我们将先将所有不带锁的题目刷完
这是我们「刷穿 LeetCode」系列文章的第 `No.1006` 篇,系列开始于 2021/01/01,截止于起始日 LeetCode 上共有 1916 道题目,部分是有锁题,我们将先把所有不带锁的题目刷完

在这个系列文章里面,除了讲解解题思路以外,还会尽可能给出最为简洁的代码。如果涉及通解还会相应的代码模板。

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ Tag : 「二分」
**由此,我们可以确定二分的范围为 $[max, sum]$。**

代码:
```Java []
```Java
class Solution {
public int shipWithinDays(int[] ws, int d) {
int max = 0, sum = 0;
Expand Down Expand Up @@ -123,7 +123,7 @@ class Solution {
*PS. 由于二分查找具有折半效率,因此「确立粗略二分范围」不会比「通过循环取得精确二分范围」效率低。*

代码:
```Java []
```Java
class Solution {
public int shipWithinDays(int[] ws, int d) {
int l = 1, r = (int)1e8;
Expand Down Expand Up @@ -183,7 +183,7 @@ class Solution {

### 最后

这是我们「刷穿 LeetCode」系列文章的第 `No.1011` 篇,系列开始于 2021/01/01,截止于起始日 LeetCode 上共有 1916 道题目,部分是有锁题,我们将先将所有不带锁的题目刷完
这是我们「刷穿 LeetCode」系列文章的第 `No.1011` 篇,系列开始于 2021/01/01,截止于起始日 LeetCode 上共有 1916 道题目,部分是有锁题,我们将先把所有不带锁的题目刷完

在这个系列文章里面,除了讲解解题思路以外,还会尽可能给出最为简洁的代码。如果涉及通解还会相应的代码模板。

Expand Down
4 changes: 2 additions & 2 deletions LeetCode/1031-1040/1035. 不相交的线(中等).md
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ $$
上述分析过程建议加深理解,估计很多同学能 AC 但其实并不知道 LCS 问题的状态转移是包含了「重复状态比较」的。

代码:
```Java []
```Java
class Solution {
public int maxUncrossedLines(int[] s1, int[] s2) {
int n = s1.length, m = s2.length;
Expand All @@ -112,7 +112,7 @@ class Solution {

### 最后

这是我们「刷穿 LeetCode」系列文章的第 `No.1035` 篇,系列开始于 2021/01/01,截止于起始日 LeetCode 上共有 1916 道题目,部分是有锁题,我们将先将所有不带锁的题目刷完
这是我们「刷穿 LeetCode」系列文章的第 `No.1035` 篇,系列开始于 2021/01/01,截止于起始日 LeetCode 上共有 1916 道题目,部分是有锁题,我们将先把所有不带锁的题目刷完

在这个系列文章里面,除了讲解解题思路以外,还会尽可能给出最为简洁的代码。如果涉及通解还会相应的代码模板。

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ class Solution {

### 最后

这是我们「刷穿 LeetCode」系列文章的第 `No.1047` 篇,系列开始于 2021/01/01,截止于起始日 LeetCode 上共有 1916 道题目,部分是有锁题,我们将先将所有不带锁的题目刷完
这是我们「刷穿 LeetCode」系列文章的第 `No.1047` 篇,系列开始于 2021/01/01,截止于起始日 LeetCode 上共有 1916 道题目,部分是有锁题,我们将先把所有不带锁的题目刷完

在这个系列文章里面,除了讲解解题思路以外,还会尽可能给出最为简洁的代码。如果涉及通解还会相应的代码模板。

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ $$f[i][j] = \max(f[i - 1][j], f[i - 1][j - stones[i - 1]] + stones[i - 1])$$
建议直接上手写「一维空间优化」版本,是其他背包问题的基础。

代码:
```Java []
```Java
class Solution {
public int lastStoneWeightII(int[] ss) {
int n = ss.length;
Expand All @@ -129,7 +129,7 @@ class Solution {
}
}
```
```Java []
```Java
class Solution {
public int lastStoneWeightII(int[] ss) {
int n = ss.length;
Expand All @@ -149,7 +149,7 @@ class Solution {
}
}
```
```Java []
```Java
class Solution {
public int lastStoneWeightII(int[] ss) {
int n = ss.length;
Expand All @@ -174,7 +174,7 @@ class Solution {

### 最后

这是我们「刷穿 LeetCode」系列文章的第 `No.1049` 篇,系列开始于 2021/01/01,截止于起始日 LeetCode 上共有 1916 道题目,部分是有锁题,我们将先将所有不带锁的题目刷完
这是我们「刷穿 LeetCode」系列文章的第 `No.1049` 篇,系列开始于 2021/01/01,截止于起始日 LeetCode 上共有 1916 道题目,部分是有锁题,我们将先把所有不带锁的题目刷完

在这个系列文章里面,除了讲解解题思路以外,还会尽可能给出最为简洁的代码。如果涉及通解还会相应的代码模板。

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ Tag : 「前缀和」、「哈希表」
数据范围是 $10^2$,对应的计算量是 $10^8$,处于超时边缘,但当我们枚举「矩阵右下角」$(i,j)$ 的时候,我们只需要搜索位于 $(i,j)$ 的左上方的点 $(p,q)$ 作为「矩阵左上角」,所以其实我们是取不满 $m^2 * n^2$ 的,但仍然具有超时风险(2021/05/29 Java 测试可通过)。

代码:
```Java []
```Java
class Solution {
public int numSubmatrixSumTarget(int[][] mat, int t) {
int n = mat.length, m = mat[0].length;
Expand Down Expand Up @@ -98,7 +98,7 @@ class Solution {
![image.png](https://pic.leetcode-cn.com/1622250565-sdYzhq-image.png)

代码:
```Java []
```Java
class Solution {
public int numSubmatrixSumTarget(int[][] mat, int t) {
int n = mat.length, m = mat[0].length;
Expand Down Expand Up @@ -142,7 +142,7 @@ class Solution {

### 最后

这是我们「刷穿 LeetCode」系列文章的第 `No.1074` 篇,系列开始于 2021/01/01,截止于起始日 LeetCode 上共有 1916 道题目,部分是有锁题,我们将先将所有不带锁的题目刷完
这是我们「刷穿 LeetCode」系列文章的第 `No.1074` 篇,系列开始于 2021/01/01,截止于起始日 LeetCode 上共有 1916 道题目,部分是有锁题,我们将先把所有不带锁的题目刷完

在这个系列文章里面,除了讲解解题思路以外,还会尽可能给出最为简洁的代码。如果涉及通解还会相应的代码模板。

Expand Down
Loading

0 comments on commit 1fca173

Please sign in to comment.