
力扣-数组
紫薯芋圆
这个作者很懒,什么都没留下…
展开
-
27.移除元素E
一、双指针 右指针指向当前要处理的元素,左指针指向下一个将要赋值的元素。 如果右指针指向的元素!=val,将右指针的元素复制到左指针位置,然后将左右指针同时右移 如果右指针指向的元素==val,左指针不动,右指针右移一位。 class Solution { public int removeElement(int[] nums, int val) { int n = nums.length; int left = 0; for (int ..原创 2021-04-25 16:15:29 · 164 阅读 · 0 评论 -
1&15&16&18 n数之和
1.两数之和 class Solution { public int[] twoSum(int[] nums, int target) { int n = nums.length; for (int i = 0; i < n; ++i) { for (int j = i + 1; j < n; ++j) { if (nums[i] + nums[j] == target) {原创 2021-04-25 15:56:28 · 170 阅读 · 0 评论 -
11.盛水最多的容器
双指针 class Solution { public int maxArea(int[] height) { int size=height.length; int left=0,right=size-1; int ans=0; while(left<right){ int area=Math.min(height[left],height[right])*(right-left); ..原创 2021-04-20 09:46:17 · 80 阅读 · 0 评论 -
15.三数之和M
关键:去重 aslist用法: class Solution { public static List<List<Integer>> threeSum(int[] nums) { List<List<Integer>> ans=new ArrayList<List<Integer>>(); int size=nums.length; if(size<3) retur..原创 2021-04-20 10:31:57 · 91 阅读 · 0 评论