多多色-多人伦交性欧美在线观看-多人伦精品一区二区三区视频-多色视频-免费黄色视屏网站-免费黄色在线

國內(nèi)最全IT社區(qū)平臺 聯(lián)系我們 | 收藏本站
阿里云優(yōu)惠2
您當前位置:首頁 > php開源 > php教程 > leetcode-26 Remove Duplicates from Sorted Array

leetcode-26 Remove Duplicates from Sorted Array

來源:程序員人生   發(fā)布時間:2015-08-17 09:17:37 閱讀次數(shù):3474次


問題描寫:

Givena sorted array, remove the duplicates in place such that each element appearonly once and return the new length.

Do not allocate extra space for another array, youmust do this in place with constant memory.

For example,
Given input array A = 
[1,1,2],

Your function should return length = 2, and A isnow [1,2].

問題分析:使用1個count統(tǒng)計不同的元素個數(shù),然后注意A[count] = A[i]來消除重復元素便可

代碼:

public class Solution { public int removeDuplicates(int[] A) { if(A == null || A.length == 0) return 0; int count = 1; for(int i = 1; i < A.length; i++) { if(A[i] != A[i - 1]) { //更新A[count] A[count] = A[i]; //更新count count ++; } } return count; } }

生活不易,碼農(nóng)辛苦
如果您覺得本網(wǎng)站對您的學習有所幫助,可以手機掃描二維碼進行捐贈
程序員人生
------分隔線----------------------------
分享到:
------分隔線----------------------------
關(guān)閉
程序員人生
主站蜘蛛池模板: 手机视频在线 | 最新国产在线播放 | 久久ri精品高清一区二区三区 | 日韩五月| 交在线观看网站视频 | 欧美性f| 国内自拍视频在线看免费观看 | 亚洲欧美另类色妞网站 | 3344成年站福利在线视频免费 | 97av在线播放 | 欧美亚洲综合在线观看 | 日韩欧美亚洲国产高清在线 | www.亚洲国产 | 国产嫩草影院精品免费网址 | 国内精品18videosex性欧美 | 亚洲一本 | 欧美free嫩交videoxxx | 精品一区二区三区免费观看 | 欧美一级高清片免费一级 | 操操久久 | 伊人久久久久久久久久 | 精品午夜国产在线观看不卡 | 最新欧美一级视频 | 欧美一区二区三区四区视频 | 精品国产理论在线观看不卡 | 欧美成人精品高清在线观看 | 亚洲黄色中文字幕 | 亚洲 欧美 自拍 另类 | 国产女乱淫真高清免费视频 | jizz日本| 五月天伊人 | 亚洲成在人线av | 精品女人 | 日本午夜在线观看 | 亚洲伊人久久大香线蕉苏妲己 | 精品一区二区三区四区在线 | 欧美成人一区二区三区不卡视频 | 第一页在线观看 | 欧美人与性另类 | 亚洲天堂手机版 | 手机福利视频 |