Integer Array Ladder questions
1.这个题不难,关键在于把题目意思理解好了。这个题问的不清楚。要求return new length,很容易晕掉。
其实就是return 有多少个单独的数。
import java.util.Arrays; /*
* Question: Given a sorted array,remove the duplicates in place such that each element
* appear only once and return the new length
*
* Do not allocate extra space for another array, you must do this in place with constant memory.
*/
public class RemoveDuplicatesfromSortedArray {
public static void main(String[] args){
int[] nums = new int[]{1,1,2};
removeDuplicates(nums);
}
public static int removeDuplicates(int[] nums){
if(nums == null || nums.length == 0){
return 0;
}
int index = 1;
for(int i=1 ;i<nums.length;i++){
if(nums[i] != nums[i-1]){
index ++;
}
}
nums = Arrays.copyOf(nums, index); return index;
}
public static int removeDuplicatesWorking(int[] nums){ return 0;
}
}
Integer Array Ladder questions的更多相关文章
- zenefits oa - sort integer array in lexographical order
[ 12 | 2434 | 23 | 1 | 654 | 222 | 56 | 100000 ] Then the output should be: [ 1 | 100000 | 12 | 222 ...
- Equal Sides Of An Array
参考:http://stackoverflow.com/questions/34584416/nested-loops-with-arrays You are going to be given an ...
- array题目合集
414. Third Maximum Number 给一个非空的整数数组,找到这个数组中第三大的值,如果不存在,那么返回最大的值.要求时间复杂度为o(n) 例如: Example 1: Input: ...
- [LeetCode] 330. Patching Array 数组补丁
Given a sorted positive integer array nums and an integer n, add/patch elements to the array such th ...
- [LeetCode] 805. Split Array With Same Average 用相同均值拆分数组
In a given integer array A, we must move every element of A to either list B or list C. (B and C ini ...
- LeetCode面试常见100题( TOP 100 Liked Questions)
LeetCode面试常见100题( TOP 100 Liked Questions) 置顶 2018年07月16日 11:25:22 lanyu_01 阅读数 9704更多 分类专栏: 面试编程题真题 ...
- [LeetCode] Minimum Moves to Equal Array Elements II 最少移动次数使数组元素相等之二
Given a non-empty integer array, find the minimum number of moves required to make all array element ...
- [LeetCode] Minimum Moves to Equal Array Elements 最少移动次数使数组元素相等
Given a non-empty integer array of size n, find the minimum number of moves required to make all arr ...
- [LeetCode] Patching Array 补丁数组
Given a sorted positive integer array nums and an integer n, add/patch elements to the array such th ...
随机推荐
- leetcode102
本题是广度优先遍历(BFS)实现树的层次遍历,使用队列实现. class Solution { public: vector<vector<int>> levelOrder(T ...
- GDI+_SavePic
Option Explicit Private Const EncoderQuality As String = "{1D5BE4B5-FA4A-452D-9CDD-5DB35105E7EB ...
- Linux网络编程学习(一) ----- 概论和Linux模型(第一章第二章)
1.什么是计算机网络,通信方式是什么? 计算机网络就是通过通信线路相互连接的计算机的集合,主要通过双绞线.同轴电缆.电话线或者光缆等有形传输介质通信,还有就是通过激光.微波.卫星等实现无线通信 2.W ...
- Ado.net之连接数据库
一.Ado.net的核心 Ado.net的核心为两组重要的类,一个负责处理软件内部的实际数据(DataSet),另一个负责与外部数据系统通信(DataProvider) DataSet:包含一个或多个 ...
- vue.js简单添加和删除
这只是个简单的添加和删除,没有连接后台数据的 <%@ page language="java" contentType="text/html; charset=UT ...
- ntp时间同步参考
https://blog.csdn.net/kamereon/article/details/54344114
- 在网站中使用UEditor富文本编辑器
UEditor是由百度WEB前端研发部开发的所见即所得的开源富文本编辑器,具有轻量.可定制.用户体验优秀等特点. 官网链接 进入到下载页面,选择相应的版本下载 这里我们使用ASP.NET开发,所以选择 ...
- Windows server 2012 R2 解决“无法完成域加入,原因是试图加入的域的SID与本计算机的SID相同
Windows server 2012 R2 解决“无法完成域加入,原因是试图加入的域的SID与本计算机的SID相同.”使用克隆的系统时,加域是出现如下问题.“无法完成域加入,原因是试图加入的域的SI ...
- Win7上安装scapy
1.环境 操作环境:win7 python版本:python3.5 依赖模块:Npcap(推荐)或WinPcap 下载scapy 2.安装步骤 操作环境,python及依赖模块安装省略(一直点击下一步 ...
- AFNetWorking 源码粗浅理解
最近在看AFNetWorking的源码,整理出自己的一点思路.先从一个最简单的网络请求看: NSString *urlStr = [NSString stringWithFormat:@"h ...