100_remove-duplicates-from-sorted-array
/*
@Copyright:LintCode
@Author: Monster__li
@Problem: http://www.lintcode.com/problem/remove-duplicates-from-sorted-array
@Language: Java
@Datetime: 17-03-02 11:26
*/
public class Solution {
/**
* @param A: a array of integers
* @return : return an integer
*/
public int removeDuplicates(int[] nums) {
// write your code here
int i,k,length=nums.length;
//显示元数组
/*System.out.println("元数组为:");
for(i=0;i<length;i++)
{
System.out.print(nums[i]+" ");
}*/
//找到重复的数字,并将后面所有元素前移一位
for(i=0;i<length-1;i++)
{
if(nums[i+1]==nums[i])
{
for(k=i+1;k<length-1;k++)
{
nums[k]=nums[k+1];
}
length--;
nums[k]=-1;
i--;
}
}
//A[i]=(-1);
//输出处理后的数组
// System.out.println("\n处理后的数组为:");
/*for(i=0;i<length;i++)
{
System.out.print(nums[i]);
}*/
return length;
}
}
100_remove-duplicates-from-sorted-array的更多相关文章
- [LeetCode] Remove Duplicates from Sorted Array II 有序数组中去除重复项之二
Follow up for "Remove Duplicates":What if duplicates are allowed at most twice? For exampl ...
- [LeetCode] Remove Duplicates from Sorted Array 有序数组中去除重复项
Given a sorted array, remove the duplicates in place such that each element appear only once and ret ...
- Remove Duplicates From Sorted Array
Remove Duplicates from Sorted Array LeetCode OJ Given a sorted array, remove the duplicates in place ...
- 【leetcode】Remove Duplicates from Sorted Array II
Remove Duplicates from Sorted Array II Follow up for "Remove Duplicates":What if duplicate ...
- 26. Remove Duplicates from Sorted Array
题目: Given a sorted array, remove the duplicates in place such that each element appear only once and ...
- 50. Remove Duplicates from Sorted Array && Remove Duplicates from Sorted Array II && Remove Element
Remove Duplicates from Sorted Array Given a sorted array, remove the duplicates in place such that e ...
- LeetCode:Remove Duplicates from Sorted Array I II
LeetCode:Remove Duplicates from Sorted Array Given a sorted array, remove the duplicates in place su ...
- 【26】Remove Duplicates from Sorted Array
[26]Remove Duplicates from Sorted Array Given a sorted array, remove the duplicates in place such th ...
- leetCode 26.Remove Duplicates from Sorted Array(删除数组反复点) 解题思路和方法
Remove Duplicates from Sorted Array Given a sorted array, remove the duplicates in place such that e ...
- [Leetcode] Remove Duplicates From Sorted Array II (C++)
题目: Follow up for "Remove Duplicates":What if duplicates are allowed at most twice? For ex ...
随机推荐
- 【Zookeeper】源码分析之服务器(二)
一.前言 前面阐述了服务器的总体框架,下面来分析服务器的所有父类ZooKeeperServer. 二.ZooKeeperServer源码分析 2.1 类的继承关系 public class ZooKe ...
- 解决https证书验证不通过的问题
1.报错信息 java.security.cert.CertificateException: No name matching api.weibo.com found; nested excepti ...
- 3步轻松搭建Unity3d安卓开发环境
之前写过一个Untiy3d安卓开发环境的配置教程,那是我第一次学习配置安卓开发环境,互联网上的信息良莠不齐,自己当时也不懂,配置步骤麻烦的一塌糊涂,现在见的多了,也会的多了,配置安卓开发环境变得非常容 ...
- DOM的内部插入和外部插入
/*****************返回值都是最前面调用这个方法的元素 ***************** */ //这是外部插入 $("div").insertBefore($( ...
- iOS网络编程笔记——社交网络编程
社交网络编程主要使用iOS提供的social框架,目前social框架主要分为两个类: (1)SLComposeViewController提供撰写社交信息(如微博信息)的视图控制器,由iOS系统提供 ...
- Linux学习之Vim使用
一 为何要学Vim 所有的Unix Like系统都有自带vi编辑器 一些软件的编辑接口会自动调起vi 作为vi的升级版,vim具有程序编辑功能,而且具有代码颜色高亮显示.辨别代码的正确性等功能 以上优 ...
- JSP配置了虚拟目录使用JavaBean报错
今天遇到一个很棘手的问题,在jsp文件中使用useBean,网页返回码出现了500服务器内部错误,报错信息如下: The value for the useBean class attribute w ...
- Android 5.0及以上版本使用webview不能存储第三方Cookies解决方案
Android 5.0以上的手机使用原生WebView浏览网页,在进行登录的时候会提示验证码错误,通过查找5.0以上系统的api文档,发现5.0以上版本的webview做了较大的改动,如:同步cook ...
- iOS开发之MapKit
1.概述 MapKit框架使用前提: 导入框架: 导入主头文件: #import <MapKit/MapKit.h> MapKit框架使用须知: MapKit框架中所有数据类型的前缀都是M ...
- 快乐Node码农的十个习惯 转
从问世到现在将近20年,JavaScript一直缺乏其它有吸引力的编程语言,比如Python和Ruby,的很多优点:命令行界面,REPL,包管理器,以及组织良好的开源社区.感谢Node.js和npm, ...