From 6929c3b862f7b28c21eae08a4f286707eec0334f Mon Sep 17 00:00:00 2001 From: CyC2018 <1029579233@qq.com> Date: Thu, 22 Feb 2018 16:27:00 +0800 Subject: [PATCH] auto commit --- notes/Leetcode 题解.md | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/notes/Leetcode 题解.md b/notes/Leetcode 题解.md index 26976634..cd3f887b 100644 --- a/notes/Leetcode 题解.md +++ b/notes/Leetcode 题解.md @@ -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 partitionLabels(String S) { List ret = new ArrayList<>(); @@ -338,6 +347,8 @@ public List 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]] @@ -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() { 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;