Skip to content

Commit

Permalink
auto commit
Browse files Browse the repository at this point in the history
  • Loading branch information
CyC2018 committed Feb 22, 2018
1 parent 17ef716 commit 6929c3b
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions notes/Leetcode 题解.md
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,15 @@ public boolean isSubsequence(String s, String t) {

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

```java
Input: S = "ababcbacadefegdehijhklij"
Output: [9,7,8]
Explanation:
The partition is "ababcbaca", "defegde", "hijhklij".
This is a partition so that each letter appears in at most one part.
A partition like "ababcbacadefegde", "hijhklij" is incorrect, because it splits S into less parts.
```

```java
public List<Integer> partitionLabels(String S) {
List<Integer> ret = new ArrayList<>();
Expand All @@ -338,6 +347,8 @@ public List<Integer> partitionLabels(String S) {

**根据身高和序号重组队列**

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

```html
Input:
[[7,0], [4,4], [7,1], [5,0], [6,1], [5,2]]
Expand All @@ -346,19 +357,21 @@ Output:
[[5,0], [7,0], [5,2], [6,1], [4,4], [7,1]]
```

一个学生用两个分量 (h, k) 描述,h 表示身高,k 表示排在前面的有 k 个学生的身高比他高或者和他一样高。
题目描述:一个学生用两个分量 (h, k) 描述,h 表示身高,k 表示排在前面的有 k 个学生的身高比他高或者和他一样高。

先排序:身高降序、k 值升序,然后按排好序的顺序插入队列的第 k 个位置中。
为了在每次插入操作时不影响后续的操作,身高较高的学生应该先做插入操作,否则身高较小的学生原先正确插入第 k 个位置可能会变成第 k+1 个位置。

身高降序、k 值升序,然后按排好序的顺序插入队列的第 k 个位置中。

```java
public int[][] reconstructQueue(int[][] people) {
if(people == null || people.length == 0 || people[0].length == 0) return new int[0][0];

Arrays.sort(people, new Comparator<int[]>() {
public int compare(int[] a, int[] b) {
if(a[0] == b[0]) return a[1] - b[1];
return b[0] - a[0];
}
}
});

int n = people.length;
Expand Down

0 comments on commit 6929c3b

Please sign in to comment.