随笔分类 -  数组

摘要: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 阅读全文
posted @ 2022-02-23 22:51 明卿册 阅读(20) 评论(0) 推荐(0) 编辑
摘要:题目链接:https://leetcode-cn.com/problems/remove-element/ 方法1——首位指针 首指针在头,尾指针在末尾,如果首指针指的是val,则交换。 public int removeElement(int[] nums, int val) { int l = 阅读全文
posted @ 2022-02-13 15:07 明卿册 阅读(21) 评论(0) 推荐(0) 编辑
摘要:public List<List<Integer>> threeSum(int[] nums) { List<List<Integer>> ans = new ArrayList<>(); List<Integer> combine = new ArrayList<>(); dfs(nums, an 阅读全文
posted @ 2022-02-06 21:42 明卿册 阅读(24) 评论(0) 推荐(0) 编辑
摘要: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][ 阅读全文
posted @ 2022-02-06 21:32 明卿册 阅读(16) 评论(0) 推荐(0) 编辑
摘要: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 阅读全文
posted @ 2022-02-04 21:31 明卿册 阅读(22) 评论(0) 推荐(0) 编辑

点击右上角即可分享
微信分享提示