去掉一个已经排好序的数组的重复数字呢
去掉一个已经排好序的数组的重复数字,速度尽量快
import il.*;
public class DelCopy{
public static void main(String[] args)
{
int[] oNums ={1,2,2,3,3,3,4,4,4,4,5,5,5,5,5};
List Integer nNums = new ArrayList Integer();
int temp =oNums[0];
d(temp);
for(int i=1;i ngth;i++)
{
if(oNums[i]temp)
{
d(oNums[i]);
temp=oNums[i];
}
}
int(nNums);
}
}
Java code
public class Test {
public static List printMap1(String[] s) {
ListString list = new LinkedListString ();
ListString list2 = List(s);
dAll(list2);
return list;
}
//去除数组中重复数据
public static String[] array_unique(String[] a) {
// array_unique
ListString list = new LinkedListString ();
for (int i = 0; i ngth; i++) {
if (!ntains(a[i])) {
d(a[i]);
}
}
return (String[]) Array(new String[ze()]);
}
public static void main(String[] args) {
String[] ar = { \"cc\", \"dd\", \"cc\", \"ee\", \"ff\", \"gg\", \"cc\", \"ee\"};
String[] s = array_unique(ar);
for (String aa : s) {
intln(aa);
}
}
}
int[] nums1 ={1,2,2,3,3,3,4,4,4,4,5,5,5,5,5};
final int LENGTH = ngth;
int[] nums2 = new int[LENGTH];
nums2[0] = nums1[0];
if(nums1[0]==nums1[LENGTH-1]){
intln(nums2);
}else{
int j = 1;
for(int i=1;i LENGTH;i++){
if(nums1[i]==nums1[i-1]){
continue;
}else{
nums2[j] = nums1[i];
j++;
}
}
}
Java code
而《纽约邮报》的专栏作家皮特-维克希对于这篇报道的真实性产生了深深的质疑 public class Sample
{
public static void main(String[] args)
{
int[] array = {1, 2, 3, 3, 5, 6, 7, 8, 8, 8, 10, 12, 13, 13, 15, 20};
long s = noTime();
int len = ngth;
int[] temp = new int[len];
int i = 0;
int j = 0;
temp[j] = array[i];
while (i len)
{
if (array[i++] != temp[j])
{
temp[++j] = array[i - 1];
}
}
int[] result = new int[++j];
raycopy(temp, 0, result, 0, j);
long e = noTime();
intln(\"TIME=\" + (e - s));
// for (int k = 0; k ngth; k++)
// {
// intln(result[k]);
// }
}
}
潍坊白癜风医院哪家好内江看白癜风医院
郑州看白癜风医院
-
中国惨绝曼联被利物浦虐哭保级队都没这么惨
云计算 | 2020-09-10
-
高雄市政府证实鸿海确定投资高雄购12万坪
云计算 | 2019-07-16
-
毛小平培育领军企业加速推进物联网产业
云计算 | 2019-07-15