随笔分类 - 数组
摘要:public int subarraySum(int[] nums, int k) { int len = nums.length, ans = 0, pre = 0; Map<Integer, Integer> map = new HashMap<>(); map.put(0,1); for(in
阅读全文
摘要:题目链接:https://leetcode-cn.com/problems/remove-element/ 方法1——首位指针 首指针在头,尾指针在末尾,如果首指针指的是val,则交换。 public int removeElement(int[] nums, int val) { int l =
阅读全文
摘要:public List<List<Integer>> threeSum(int[] nums) { List<List<Integer>> ans = new ArrayList<>(); List<Integer> combine = new ArrayList<>(); dfs(nums, an
阅读全文
摘要:public void rotate(int[][] matrix) { int n = matrix.length, m= n-1; for(int i = 0; i < n/2; i++) { for(int j = 0; j < n/2; j++) { int tmp = matrix[i][
阅读全文
摘要:public int maxProfit(int[] prices) { if(prices.length < 2) return 0; int ans = 0, beforeMin = prices[0]; for(int i =1; i < prices.length; i++) { int p
阅读全文