Leetcode #27. Remove Element 移除元素 解题报告
来源:互联网 发布:悠唐网络是真的吗 编辑:程序博客网 时间:2024/05/20 19:16
1 解题思想
原题不就是说,给定数组,和一个目标值。。把数组里等于目标值的给删了么,最后还剩几个。。
这道题虽然只说有几个。。但是似乎还是要交换的,不只是单纯的统计。。检查的时候会遍历检查的
2 原题
原题
Given an array and a value, remove all instances of that value in place and return the new length.
Do not allocate extra space for another array, you must do this in place with constant memory.
The order of elements can be changed. It doesn’t matter what you leave beyond the new length.
Example:
Given input array nums = [3,2,2,3], val = 3
Your function should return length = 2, with the first two elements of nums being 2.
3 AC解
public class Solution { /** * 这世道水题,做法很简单,一个当前位置i一个当前长度n,顺着找,如果相等就把当前有效位置的最后一个放倒i上就好,然后n--,自然就没了 * 如果不是的话,i++,继续找下一个,就这样 */ public int removeElement(int[] nums, int val) { int n=nums.length; int i=0; while(i<n){ if(nums[i]==val){ n--; nums[i]=nums[n]; } else{ i++; } } return n; }}
0 0
- Leetcode #27. Remove Element 移除元素 解题报告
- [leetcode] 27. Remove Element 解题报告
- [Leetcode] 27. Remove Element 解题报告
- 【LeetCode】27.Remove Element(Easy)解题报告
- LeetCode Remove Element 解题报告
- LeetCode解题报告--Remove Element
- [LeetCode] Remove Element 解题报告
- 【LeetCode】Remove Element 解题报告
- Leetcode Remove Element解题报告
- Remove Element 移除元素
- LeetCode 27 Remove Element(移除元素)
- Leetcode 27 Remove Element(移除数组中的指定元素)
- Leetcode刷题记——27. Remove Element(移除数组元素)
- leetCode 27.Remove Element (删除元素) 解题思路和方法
- Remove Element--原地移除重复元素
- leetcode 27 Remove Element(移除数组中的与val相等的元素)
- Leetcode #26. Remove Duplicates from Sorted Array 移除重复数字 解题报告
- Leetcode 80. Remove Duplicates from Sorted Array II 重复移除 解题报告
- [Android 系统源代码研究] SystemService启动
- LeetCode 313. Super Ugly Number
- Android第五周的学习笔记
- pods安装
- python 出现错误 SyntaxError: Non-ASCII character 的解决方法
- Leetcode #27. Remove Element 移除元素 解题报告
- JavaScript Math.floor()
- poj3984迷宫问题
- 设计模式学习笔记——桥接模式
- Scanner类的使用
- Java >>> 详解
- MySQL性能分析
- 1-1-JS中的HTML属性操作
- AOJ 0118 Property Distribution(dfs 求连通块)