Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 1c6ad04

Browse files
Update
1 parent 0df748c commit 1c6ad04

10 files changed

+100
-111
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
<a href="https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ"><img src="https://img.shields.io/badge/知识星球-代码随想录-blue" alt=""></a>
2323
</p>
2424

25-
<p align="center"><strong>《代码随想录》正式出版啦!!录友专属福利,点击下方可以享五折优惠!详细可以<a href="programmercarl.com/other/publish.html">点击这里</a></strong></p>
25+
<p align="center"><strong>《代码随想录》正式出版啦!!录友专属福利,点击下方可以享五折优惠!详细可以<a href="https://programmercarl.com/other/publish.html">点击这里</a></strong></p>
2626

2727
<p align="center">
2828
<a href="https://union-click.jd.com/jdc?e=&p=JF8BAMQJK1olXg8EUVhVCkkWAV8IGV8WVAICU24ZVxNJXF9RXh5UHw0cSgYYXBcIWDoXSQVJQwYAUF1UDEsQHDZNRwYlX0B9A1cfakpyYBkSRj4QKFBUEEAfaEcbM244GFIXWQYAUV5VOHsXBF9edVsUXAcDVVtdDUgnAl8IHFkdXw8KUl5fDkgRM2gIEmtIFVpKAxVtOHsUM184G2sWbURsVApfAR8XA2sLSw8cWA8LUw1ZCElHAmhdTAxGW1YBUlxtCkoWB2Y4" target="_blank">

problems/0015.三数之和.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public:
5555
for (int i = 0; i < nums.size(); i++) {
5656
// 排序之后如果第一个元素已经大于零,那么不可能凑成三元组
5757
if (nums[i] > 0) {
58-
continue;
58+
break;
5959
}
6060
if (i > 0 && nums[i] == nums[i - 1]) { //三元组元素a去重
6161
continue;

problems/0018.四数之和.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,8 @@ public:
9191
// nums[k] + nums[i] + nums[left] + nums[right] > target 会溢出
9292
if (nums[k] + nums[i] > target - (nums[left] + nums[right])) {
9393
right--;
94-
} else if (nums[k] + nums[i] + nums[left] + nums[right] < target) {
94+
// nums[k] + nums[i] + nums[left] + nums[right] < target 会溢出
95+
} else if (nums[k] + nums[i] < target - (nums[left] + nums[right])) {
9596
left++;
9697
} else {
9798
result.push_back(vector<int>{nums[k], nums[i], nums[left], nums[right]});
@@ -111,6 +112,7 @@ public:
111112
}
112113
};
113114

115+
114116
```
115117

116118

problems/0056.合并区间.md

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,22 @@
55
<p align="center"><strong><a href="https://mp.weixin.qq.com/s/tqCxrMEU-ajQumL1i8im9A">参与本项目</a>,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们收益!</strong></p>
66

77

8-
## 56. 合并区间
8+
# 56. 合并区间
99

1010
[力扣题目链接](https://leetcode-cn.com/problems/merge-intervals/)
1111

1212
给出一个区间的集合,请合并所有重叠的区间。
1313

1414
示例 1:
15-
输入: intervals = [[1,3],[2,6],[8,10],[15,18]]
16-
输出: [[1,6],[8,10],[15,18]]
17-
解释: 区间 [1,3][2,6] 重叠, 将它们合并为 [1,6].
15+
* 输入: intervals = [[1,3],[2,6],[8,10],[15,18]]
16+
* 输出: [[1,6],[8,10],[15,18]]
17+
* 解释: 区间 [1,3][2,6] 重叠, 将它们合并为 [1,6].
1818

1919
示例 2:
20-
输入: intervals = [[1,4],[4,5]]
21-
输出: [[1,5]]
22-
解释: 区间 [1,4][4,5] 可被视为重叠区间。
23-
注意:输入类型已于2019年4月15日更改。 请重置默认代码定义以获取新方法签名。
20+
* 输入: intervals = [[1,4],[4,5]]
21+
* 输出: [[1,5]]
22+
* 解释: 区间 [1,4][4,5] 可被视为重叠区间。
23+
* 注意:输入类型已于2019年4月15日更改。 请重置默认代码定义以获取新方法签名。
2424

2525
提示:
2626

@@ -134,7 +134,7 @@ public:
134134
## 其他语言版本
135135

136136

137-
Java
137+
### Java
138138
```java
139139
class Solution {
140140
public int[][] merge(int[][] intervals) {
@@ -178,7 +178,7 @@ class Solution {
178178
}
179179
```
180180

181-
Python
181+
### Python
182182
```python
183183
class Solution:
184184
def merge(self, intervals: List[List[int]]) -> List[List[int]]:
@@ -195,7 +195,7 @@ class Solution:
195195
return result
196196
```
197197

198-
Go:
198+
### Go
199199
```golang
200200
func merge(intervals [][]int) [][]int {
201201
//先从小到大排序
@@ -220,7 +220,7 @@ func max(a,b int)int{
220220
}
221221
```
222222

223-
Javascript
223+
### Javascript
224224
```javascript
225225
var merge = function (intervals) {
226226
intervals.sort((a, b) => a[0] - b[0]);

problems/0435.无重叠区间.md

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<p align="center"><strong><a href="https://mp.weixin.qq.com/s/tqCxrMEU-ajQumL1i8im9A">参与本项目</a>,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们收益!</strong></p>
66

77

8-
## 435. 无重叠区间
8+
# 435. 无重叠区间
99

1010
[力扣题目链接](https://leetcode-cn.com/problems/non-overlapping-intervals/)
1111

@@ -16,19 +16,19 @@
1616
区间 [1,2][2,3] 的边界相互“接触”,但没有相互重叠。
1717

1818
示例 1:
19-
输入: [ [1,2], [2,3], [3,4], [1,3] ]
20-
输出: 1
21-
解释: 移除 [1,3] 后,剩下的区间没有重叠。
19+
* 输入: [ [1,2], [2,3], [3,4], [1,3] ]
20+
* 输出: 1
21+
* 解释: 移除 [1,3] 后,剩下的区间没有重叠。
2222

2323
示例 2:
24-
输入: [ [1,2], [1,2], [1,2] ]
25-
输出: 2
26-
解释: 你需要移除两个 [1,2] 来使剩下的区间没有重叠。
24+
* 输入: [ [1,2], [1,2], [1,2] ]
25+
* 输出: 2
26+
* 解释: 你需要移除两个 [1,2] 来使剩下的区间没有重叠。
2727

2828
示例 3:
29-
输入: [ [1,2], [2,3] ]
30-
输出: 0
31-
解释: 你不需要移除任何区间,因为它们已经是无重叠的了。
29+
* 输入: [ [1,2], [2,3] ]
30+
* 输出: 0
31+
* 解释: 你不需要移除任何区间,因为它们已经是无重叠的了。
3232

3333
## 思路
3434

@@ -179,7 +179,7 @@ public:
179179
## 其他语言版本
180180

181181

182-
Java
182+
### Java
183183
```java
184184
class Solution {
185185
public int eraseOverlapIntervals(int[][] intervals) {
@@ -209,7 +209,6 @@ class Solution {
209209
}
210210
```
211211

212-
Java:
213212
按左边排序,不管右边顺序。相交的时候取最小的右边。
214213
```java
215214
class Solution {
@@ -232,7 +231,7 @@ class Solution {
232231
}
233232
```
234233

235-
Python
234+
### Python
236235
```python
237236
class Solution:
238237
def eraseOverlapIntervals(self, intervals: List[List[int]]) -> int:
@@ -247,7 +246,7 @@ class Solution:
247246
return len(intervals) - count
248247
```
249248

250-
Go:
249+
### Go
251250
```golang
252251
func eraseOverlapIntervals(intervals [][]int) int {
253252
var flag int
@@ -270,8 +269,9 @@ func min(a,b int)int{
270269
}
271270
return a
272271
}
273-
```
274-
Javascript:
272+
```
273+
274+
### Javascript:
275275
- 按右边界排序
276276
```Javascript
277277
var eraseOverlapIntervals = function(intervals) {

problems/0714.买卖股票的最佳时机含手续费.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<p align="center"><strong><a href="https://mp.weixin.qq.com/s/tqCxrMEU-ajQumL1i8im9A">参与本项目</a>,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们收益!</strong></p>
66

77

8-
## 714. 买卖股票的最佳时机含手续费
8+
# 714. 买卖股票的最佳时机含手续费
99

1010
[力扣题目链接](https://leetcode-cn.com/problems/best-time-to-buy-and-sell-stock-with-transaction-fee/)
1111

problems/0738.单调递增的数字.md

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,24 @@
55
<p align="center"><strong><a href="https://mp.weixin.qq.com/s/tqCxrMEU-ajQumL1i8im9A">参与本项目</a>,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们收益!</strong></p>
66

77

8-
## 738.单调递增的数字
8+
# 738.单调递增的数字
99
[力扣题目链接](https://leetcode-cn.com/problems/monotone-increasing-digits/)
1010

1111
给定一个非负整数 N,找出小于或等于 N 的最大的整数,同时这个整数需要满足其各个位数上的数字是单调递增。
1212

1313
(当且仅当每个相邻位数上的数字 x 和 y 满足 x <= y 时,我们称这个整数是单调递增的。)
1414

1515
示例 1:
16-
输入: N = 10
17-
输出: 9
16+
* 输入: N = 10
17+
* 输出: 9
1818

1919
示例 2:
20-
输入: N = 1234
21-
输出: 1234
20+
* 输入: N = 1234
21+
* 输出: 1234
2222

2323
示例 3:
24-
输入: N = 332
25-
输出: 299
24+
* 输入: N = 332
25+
* 输出: 299
2626

2727
说明: N 是在 [0, 10^9] 范围内的一个整数。
2828

@@ -123,7 +123,7 @@ public:
123123
## 其他语言版本
124124

125125

126-
Java:
126+
### Java:
127127
```java
128128
版本1
129129
class Solution {
@@ -170,8 +170,8 @@ class Solution {
170170
```
171171

172172

173-
Python:
174-
```python3
173+
### Python:
174+
```python
175175
class Solution:
176176
def monotoneIncreasingDigits(self, n: int) -> int:
177177
a = list(str(n))
@@ -182,7 +182,7 @@ class Solution:
182182
return int("".join(a))
183183
```
184184

185-
Go:
185+
### Go
186186
```golang
187187
func monotoneIncreasingDigits(N int) int {
188188
s := strconv.Itoa(N)//将数字转为字符串,方便使用下标
@@ -203,7 +203,8 @@ func monotoneIncreasingDigits(N int) int {
203203
return res
204204
}
205205
```
206-
Javascript:
206+
207+
### Javascript
207208
```Javascript
208209
var monotoneIncreasingDigits = function(n) {
209210
n = n.toString()

problems/0763.划分字母区间.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@
55
<p align="center"><strong><a href="https://mp.weixin.qq.com/s/tqCxrMEU-ajQumL1i8im9A">参与本项目</a>,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们收益!</strong></p>
66

77

8-
## 763.划分字母区间
8+
# 763.划分字母区间
99

1010
[力扣题目链接](https://leetcode-cn.com/problems/partition-labels/)
1111

1212
字符串 S 由小写字母组成。我们要把这个字符串划分为尽可能多的片段,同一字母最多出现在一个片段中。返回一个表示每个字符串片段的长度的列表。
1313

1414
示例:
15-
输入:S = "ababcbacadefegdehijhklij"
16-
输出:[9,7,8]
15+
* 输入:S = "ababcbacadefegdehijhklij"
16+
* 输出:[9,7,8]
1717
解释:
1818
划分结果为 "ababcbaca", "defegde", "hijhklij"。
1919
每个字母最多出现在一个片段中。
@@ -81,7 +81,7 @@ public:
8181
## 其他语言版本
8282
8383
84-
Java
84+
### Java
8585
```java
8686
class Solution {
8787
public List<Integer> partitionLabels(String S) {
@@ -105,7 +105,7 @@ class Solution {
105105
}
106106
```
107107

108-
Python
108+
### Python
109109
```python
110110
class Solution:
111111
def partitionLabels(self, s: str) -> List[int]:
@@ -124,7 +124,7 @@ class Solution:
124124

125125
```
126126

127-
Go:
127+
### Go
128128

129129
```go
130130

@@ -153,7 +153,7 @@ func max(a, b int) int {
153153
}
154154
```
155155

156-
Javascript:
156+
### Javascript
157157
```Javascript
158158
var partitionLabels = function(s) {
159159
let hash = {}

0 commit comments

Comments
 (0)