摘要:
将数组按照绝对值的方法排序,从后往前,把绝对值大的负数变正即可。 java中自定义排序int[]比较麻烦,故我用的直接排序,用两个指针比较绝对值遍历。 class Solution { public int largestSumAfterKNegations(int[] nums, int k) { 阅读全文
摘要:
解法1:贪心。 除去中间单调的节点即可。 class Solution { public int wiggleMaxLength(int[] nums) { int n=nums.length; int ans=1; int prevSub=0; for(int i=1;i<n;i++){ int 阅读全文
摘要:
class Solution { public int findContentChildren(int[] g, int[] s) { Arrays.sort(g); Arrays.sort(s); int ans=0; for(int i=0,j=0;i<g.length&&j<s.length; 阅读全文