LeetCode 406. Queue Reconstruction by Height
2016-12-17 21:20
796 查看
public class Solution { public int[][] reconstructQueue(int[][] people) { int l = people.length; if (l == 1) return people; for (int i = l - 1; i > 0; i--) { for (int j = 0; j < i; j++) { if (people[i][1] < people[j][1]) { int[] tmp = people[i]; people[i] = people[j]; people[j] = tmp; } else if (people[i][1] == people[j][1] && people[i][0] < people[j][0]) { int[] tmp = people[i]; people[i] = people[j]; people[j] = tmp; } } } for (int i = 1; i < l; i++) { int count = 0; for (int j = 0; j < i; j++) { if (people[i][0] <= people[j][0]) count++; if (people[i][1] < count) { int[] tmp = people[i]; for (int k = i; k >= j + 1; k--) people[k] = people[k - 1]; people[j] = tmp; break; } } } return people; } }
相关文章推荐
- leetcode刷题之旅——406. Queue Reconstruction by Height
- LeetCode 406. Queue Reconstruction by Height (Medium)
- [Leetcode] 406. Queue Reconstruction by Height
- 【LeetCode】406.Queue Reconstruction by Height(Medium)解题报告
- LeetCode 406. Queue Reconstruction by Height
- [leetcode] 406. Queue Reconstruction by Height
- Leetcode-406. Queue Reconstruction by Height
- LeetCode 406. Queue Reconstruction by Height
- LeetCode406. Queue Reconstruction by Height
- leetcode 406. Queue Reconstruction by Height
- [LeetCode]406. Queue Reconstruction by Height
- 【leetcode】【M】406. Queue Reconstruction by Height【95】
- Leetcode 406. Queue Reconstruction by Height 排队重构 解题报告
- 【LeetCode】 406. Queue Reconstruction by Height
- [LeetCode]406.Queue Reconstruction by Height
- LeetCode 406. Queue Reconstruction by Height
- [LeetCode]406. Queue Reconstruction by Height
- Leetcode 406. Queue Reconstruction by Height
- LeetCode--406. Queue Reconstruction by Height
- Leetcode 406. Queue Reconstruction by Height