随笔分类 - 算法
摘要:题目: 解: public int[] plusOne(int[] digits) { int length = digits.length; for (int i = length - 1; i >= 0; i--) { if (digits[i] != 9) { //如果数组当前元素不等于9,直
阅读全文
摘要:题目: 解:双指针;map public int[] intersect(int[] nums1, int[] nums2) { // 先对两个数组进行排序 Arrays.sort(nums1); Arrays.sort(nums2); int i = 0; int j = 0; List<Inte
阅读全文
摘要:题目: 解:位运算解决;使用集合Set解决 public int singleNumber(int nums[]) { int result = 0; for (int i = 0; i < nums.length; i++) result ^= nums[i]; return result;}
阅读全文
摘要:题目: 解:Arrays.sort(nums);set集合 public boolean containsDuplicate(int[] nums) { Set<Integer> set = new HashSet<>(); for (int num : nums) { //因为集合set中不能有重
阅读全文
摘要:题目: 解:(i + k) % length class Solution { public void rotate(int nums[], int k) { int length = nums.length; int temp[] = new int[length]; //把原数组值放到一个临时数
阅读全文
摘要:题目: 解: public int maxProfit(int[] prices) { if (prices == null || prices.length < 2) return 0; int total = 0, index = 0, length = prices.length; while
阅读全文
摘要:题目: 解: 快慢双指针解决 使用两个指针,右指针始终往右移动, 如果右指针指向的值等于左指针指向的值,左指针不动。 如果右指针指向的值不等于左指针指向的值,那么左指针往右移一步,然后再把右指针指向的值赋给左指针。 public int removeDuplicates(int[] A) { //边
阅读全文

浙公网安备 33010602011771号