国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

[LeetCode] Remove Element

2019-11-15 01:06:46
字體:
來源:轉載
供稿:網友
[LeetCode] Remove Element

Given an array and a value, remove all instances of that value in place and return the new length.

The order of elements can be changed. It doesn't matter what you leave beyond the new length.

這道題也很簡單,個人認為,特別是因為只是要求remove,對order的順序也沒有改變(當然了如果愿意還是盡量可以不改變順序)。可以用個簡單的two pointer來解決。一個int用來loop,另一個int則是用來排序剩下的integer。

public class Solution {    public int removeElement(int[] nums, int val) {        int a = 0;        int b = 0;        if (nums.length==0){            return 0;        }         while( b<nums.length ) {            if ( nums[b]!=val ) {                nums[a] = nums[b];                a++;            }                   b++;        }        return a;    }}


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 嘉兴市| 南召县| 白河县| 扶沟县| 平凉市| 鄂伦春自治旗| 中牟县| 静乐县| 兴和县| 皮山县| 和顺县| 新乡市| 天水市| 宁南县| 高邮市| 兴国县| 沂源县| 泰兴市| 西安市| 丰原市| 共和县| 博客| 鄂温| 蓬溪县| 固阳县| 宽城| 正定县| 浦北县| 闻喜县| 寿阳县| 漳浦县| 菏泽市| 枣庄市| 安溪县| 虎林市| 崇礼县| 左贡县| 镇江市| 民丰县| 丽水市| 惠水县|