摘要:
1th 两数之和 暴力枚举法 直接两重循环暴力枚举,很慢。 class Solution { public int[] twoSum(int[] nums, int target) { int[] ans = new int[2]; for(int i = 0; i < nums.length; i 阅读全文
摘要:
283th 移动零 位置指示器法 我们将cnt看作位置指示器,易于发现规律:某个不为0的元素前面有几个0(cnt),他就会向前移动cnt个位置。 class Solution { public void moveZeroes(int[] nums) { int cnt = 0; for(int i 阅读全文
摘要:
136th 只出现一次的数字 先排序后处理数据 class Solution { public int singleNumber(int[] nums) { Arrays.sort(nums); boolean flag = false; int ans = 0; for(int i = 0; i 阅读全文