406. 根据身高重建队列

class Solution {//[7,0],[4,4],[7,1],[5,0],[6,1],[5,2]//[7,0],[7,1],[6,1],[5,0],[5,2],[4,4]//先按身高从高往低排序,再按第二个元素从第往高排//[7,0]//[7,0],[7,1]//[7,0],[6,1],[7,1]//[5,0],[7,0],[6,1],[7,1]//[5,0],[5,2],[7,0],[6,1],[7,1]//[5,0],[5,2],[7,0],[6,1],[4,4],[7,1]public int[][] reconstructQueue(int[][] people) {if (people == null || people.length == 0 || people[0].length != 2) return new int[0][0];Arrays.sort(people,(p1, p2) -> {if (p1[0] != p2[0]) {return p2[0] - p1[0];} else {return p1[1] - p2[1];}});List<int[]> res = new ArrayList();for (int[] p : people) {res.add(p[1], p);}return res.toArray(new int[res.size()][]);}}
55. 跳跃游戏

动态规划
class Solution {public boolean canJump(int[] nums) {if (nums == null || nums.length == 0) return false;boolean[] dp = new boolean[nums.length];//dp[i]=dp[j]&&nums[j]>=i-jdp[0] = true;for (int i = 1; i < nums.length; i++) {for (int j = i - 1; j >= 0; j--) {dp[i] |= dp[j] && nums[j] >= (i - j);if (dp[i]) break;}}return dp[nums.length - 1];}}
贪心法
class Solution {public boolean canJump(int[] nums) {if (nums == null || nums.length < 2) return true;int maxRemote = 0;for (int i = 0; i < nums.length - 1; i++) {if (i <= maxRemote) {maxRemote = Math.max(maxRemote, i + nums[i]);}if (maxRemote >= nums.length - 1) return true;}return false;}}
