Skip to content

Commit

Permalink
auto commit
Browse files Browse the repository at this point in the history
  • Loading branch information
CyC2018 committed Jun 11, 2019
1 parent a18e678 commit 1adbf87
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 48 deletions.
48 changes: 24 additions & 24 deletions docs/notes/Leetcode 题解 - 贪心思想.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
* [1. 分配饼干](#1-分配饼干)
* [2. 不重叠的区间个数](#2-不重叠的区间个数)
* [3. 投飞镖刺破气球](#3-投飞镖刺破气球)
* [3. 根据身高和序号重组队列](#3-根据身高和序号重组队列)
* [4. 买卖股票最大的收益](#4-买卖股票最大的收益)
* [5. 买卖股票的最大收益 II](#5-买卖股票的最大收益-ii)
* [6. 种植花朵](#6-种植花朵)
* [7. 判断是否为子序列](#7-判断是否为子序列)
* [8. 修改一个数成为非递减数组](#8-修改一个数成为非递减数组)
* [9. 子数组最大的和](#9-子数组最大的和)
* [10. 分隔字符串使同种字符出现在一起](#10-分隔字符串使同种字符出现在一起)
* [4. 根据身高和序号重组队列](#4-根据身高和序号重组队列)
* [5. 买卖股票最大的收益](#5-买卖股票最大的收益)
* [6. 买卖股票的最大收益 II](#6-买卖股票的最大收益-ii)
* [7. 种植花朵](#7-种植花朵)
* [8. 判断是否为子序列](#8-判断是否为子序列)
* [9. 修改一个数成为非递减数组](#9-修改一个数成为非递减数组)
* [10. 子数组最大的和](#10-子数组最大的和)
* [11. 分隔字符串使同种字符出现在一起](#11-分隔字符串使同种字符出现在一起)
<!-- GFM-TOC -->


Expand Down Expand Up @@ -78,18 +78,18 @@ Explanation: You don't need to remove any of the intervals since they're already
按区间的结尾进行排序,每次选择结尾最小,并且和前一个区间不重叠的区间。

```java
public int eraseOverlapIntervals(Interval[] intervals) {
public int eraseOverlapIntervals(int[][] intervals) {
if (intervals.length == 0) {
return 0;
}
Arrays.sort(intervals, Comparator.comparingInt(o -> o.end));
Arrays.sort(intervals, Comparator.comparingInt(o -> o[1]));
int cnt = 1;
int end = intervals[0].end;
int end = intervals[0][1];
for (int i = 1; i < intervals.length; i++) {
if (intervals[i].start < end) {
if (intervals[i][0] < end) {
continue;
}
end = intervals[i].end;
end = intervals[i][1];
cnt++;
}
return intervals.length - cnt;
Expand All @@ -99,10 +99,10 @@ public int eraseOverlapIntervals(Interval[] intervals) {
使用 lambda 表示式创建 Comparator 会导致算法运行时间过长,如果注重运行时间,可以修改为普通创建 Comparator 语句:

```java
Arrays.sort(intervals, new Comparator<Interval>() {
Arrays.sort(intervals, new Comparator<int[]>() {
@Override
public int compare(Interval o1, Interval o2) {
return o1.end - o2.end;
public int compare(int[] o1, int[] o2) {
return o1[1] - o2[1];
}
});
```
Expand Down Expand Up @@ -141,7 +141,7 @@ public int findMinArrowShots(int[][] points) {
}
```

# 3. 根据身高和序号重组队列
# 4. 根据身高和序号重组队列

[406. Queue Reconstruction by Height(Medium)](https://leetcode.com/problems/queue-reconstruction-by-height/description/)

Expand Down Expand Up @@ -173,7 +173,7 @@ public int[][] reconstructQueue(int[][] people) {
}
```

# 4. 买卖股票最大的收益
# 5. 买卖股票最大的收益

[121. Best Time to Buy and Sell Stock (Easy)](https://leetcode.com/problems/best-time-to-buy-and-sell-stock/description/)

Expand All @@ -196,7 +196,7 @@ public int maxProfit(int[] prices) {
```


# 5. 买卖股票的最大收益 II
# 6. 买卖股票的最大收益 II

[122. Best Time to Buy and Sell Stock II (Easy)](https://leetcode.com/problems/best-time-to-buy-and-sell-stock-ii/description/)

Expand All @@ -217,7 +217,7 @@ public int maxProfit(int[] prices) {
```


# 6. 种植花朵
# 7. 种植花朵

[605. Can Place Flowers (Easy)](https://leetcode.com/problems/can-place-flowers/description/)

Expand Down Expand Up @@ -247,7 +247,7 @@ public boolean canPlaceFlowers(int[] flowerbed, int n) {
}
```

# 7. 判断是否为子序列
# 8. 判断是否为子序列

[392. Is Subsequence (Medium)](https://leetcode.com/problems/is-subsequence/description/)

Expand All @@ -269,7 +269,7 @@ public boolean isSubsequence(String s, String t) {
}
```

# 8. 修改一个数成为非递减数组
# 9. 修改一个数成为非递减数组

[665. Non-decreasing Array (Easy)](https://leetcode.com/problems/non-decreasing-array/description/)

Expand Down Expand Up @@ -303,7 +303,7 @@ public boolean checkPossibility(int[] nums) {



# 9. 子数组最大的和
# 10. 子数组最大的和

[53. Maximum Subarray (Easy)](https://leetcode.com/problems/maximum-subarray/description/)

Expand All @@ -327,7 +327,7 @@ public int maxSubArray(int[] nums) {
}
```

# 10. 分隔字符串使同种字符出现在一起
# 11. 分隔字符串使同种字符出现在一起

[763. Partition Labels (Medium)](https://leetcode.com/problems/partition-labels/description/)

Expand Down
48 changes: 24 additions & 24 deletions notes/Leetcode 题解 - 贪心思想.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
* [1. 分配饼干](#1-分配饼干)
* [2. 不重叠的区间个数](#2-不重叠的区间个数)
* [3. 投飞镖刺破气球](#3-投飞镖刺破气球)
* [3. 根据身高和序号重组队列](#3-根据身高和序号重组队列)
* [4. 买卖股票最大的收益](#4-买卖股票最大的收益)
* [5. 买卖股票的最大收益 II](#5-买卖股票的最大收益-ii)
* [6. 种植花朵](#6-种植花朵)
* [7. 判断是否为子序列](#7-判断是否为子序列)
* [8. 修改一个数成为非递减数组](#8-修改一个数成为非递减数组)
* [9. 子数组最大的和](#9-子数组最大的和)
* [10. 分隔字符串使同种字符出现在一起](#10-分隔字符串使同种字符出现在一起)
* [4. 根据身高和序号重组队列](#4-根据身高和序号重组队列)
* [5. 买卖股票最大的收益](#5-买卖股票最大的收益)
* [6. 买卖股票的最大收益 II](#6-买卖股票的最大收益-ii)
* [7. 种植花朵](#7-种植花朵)
* [8. 判断是否为子序列](#8-判断是否为子序列)
* [9. 修改一个数成为非递减数组](#9-修改一个数成为非递减数组)
* [10. 子数组最大的和](#10-子数组最大的和)
* [11. 分隔字符串使同种字符出现在一起](#11-分隔字符串使同种字符出现在一起)
<!-- GFM-TOC -->


Expand Down Expand Up @@ -78,18 +78,18 @@ Explanation: You don't need to remove any of the intervals since they're already
按区间的结尾进行排序,每次选择结尾最小,并且和前一个区间不重叠的区间。

```java
public int eraseOverlapIntervals(Interval[] intervals) {
public int eraseOverlapIntervals(int[][] intervals) {
if (intervals.length == 0) {
return 0;
}
Arrays.sort(intervals, Comparator.comparingInt(o -> o.end));
Arrays.sort(intervals, Comparator.comparingInt(o -> o[1]));
int cnt = 1;
int end = intervals[0].end;
int end = intervals[0][1];
for (int i = 1; i < intervals.length; i++) {
if (intervals[i].start < end) {
if (intervals[i][0] < end) {
continue;
}
end = intervals[i].end;
end = intervals[i][1];
cnt++;
}
return intervals.length - cnt;
Expand All @@ -99,10 +99,10 @@ public int eraseOverlapIntervals(Interval[] intervals) {
使用 lambda 表示式创建 Comparator 会导致算法运行时间过长,如果注重运行时间,可以修改为普通创建 Comparator 语句:

```java
Arrays.sort(intervals, new Comparator<Interval>() {
Arrays.sort(intervals, new Comparator<int[]>() {
@Override
public int compare(Interval o1, Interval o2) {
return o1.end - o2.end;
public int compare(int[] o1, int[] o2) {
return o1[1] - o2[1];
}
});
```
Expand Down Expand Up @@ -141,7 +141,7 @@ public int findMinArrowShots(int[][] points) {
}
```

# 3. 根据身高和序号重组队列
# 4. 根据身高和序号重组队列

[406. Queue Reconstruction by Height(Medium)](https://leetcode.com/problems/queue-reconstruction-by-height/description/)

Expand Down Expand Up @@ -173,7 +173,7 @@ public int[][] reconstructQueue(int[][] people) {
}
```

# 4. 买卖股票最大的收益
# 5. 买卖股票最大的收益

[121. Best Time to Buy and Sell Stock (Easy)](https://leetcode.com/problems/best-time-to-buy-and-sell-stock/description/)

Expand All @@ -196,7 +196,7 @@ public int maxProfit(int[] prices) {
```


# 5. 买卖股票的最大收益 II
# 6. 买卖股票的最大收益 II

[122. Best Time to Buy and Sell Stock II (Easy)](https://leetcode.com/problems/best-time-to-buy-and-sell-stock-ii/description/)

Expand All @@ -217,7 +217,7 @@ public int maxProfit(int[] prices) {
```


# 6. 种植花朵
# 7. 种植花朵

[605. Can Place Flowers (Easy)](https://leetcode.com/problems/can-place-flowers/description/)

Expand Down Expand Up @@ -247,7 +247,7 @@ public boolean canPlaceFlowers(int[] flowerbed, int n) {
}
```

# 7. 判断是否为子序列
# 8. 判断是否为子序列

[392. Is Subsequence (Medium)](https://leetcode.com/problems/is-subsequence/description/)

Expand All @@ -269,7 +269,7 @@ public boolean isSubsequence(String s, String t) {
}
```

# 8. 修改一个数成为非递减数组
# 9. 修改一个数成为非递减数组

[665. Non-decreasing Array (Easy)](https://leetcode.com/problems/non-decreasing-array/description/)

Expand Down Expand Up @@ -303,7 +303,7 @@ public boolean checkPossibility(int[] nums) {



# 9. 子数组最大的和
# 10. 子数组最大的和

[53. Maximum Subarray (Easy)](https://leetcode.com/problems/maximum-subarray/description/)

Expand All @@ -327,7 +327,7 @@ public int maxSubArray(int[] nums) {
}
```

# 10. 分隔字符串使同种字符出现在一起
# 11. 分隔字符串使同种字符出现在一起

[763. Partition Labels (Medium)](https://leetcode.com/problems/partition-labels/description/)

Expand Down

0 comments on commit 1adbf87

Please sign in to comment.