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 ...
随机推荐
- javaee_正则表达式基础和常用表达式
正则基础: 1.1 -字符集 [ ] : 代表单个字符. [^] : 除了该字符外的所有单个字符. [a-zA-Z] : [a-z] || [A-Z]. [a-d[m-p]] :[a, d] || [ ...
- ElasicSearch(4) 与jest结合
https://spring.io/projects/spring-data-elasticsearch https://docs.spring.io/spring-data/elasticsearc ...
- Python单元测试unittest【转自https://www.cnblogs.com/feng0815/p/8045850.html】
[转自https://www.cnblogs.com/feng0815/p/8045850.html] Python中有一个自带的单元测试框架是unittest模块,用它来做单元测试,它里面封装好了一 ...
- win10系统goole浏览器安装postMan插件
1. 首先是下载PostMan工具,可以通过谷歌插件网站查询下载postman插件工具.解压文件 2. 解压压缩包 3. 修改_metadata文件重命名为metadata文件,保存待用.修改后为: ...
- Collection中的方法
以ArrayList为例 package com.mydemo; import java.util.ArrayList; public class CollectionDemo { public st ...
- WMS常用表
--主数据 select * from sku; select * from pack; select * from userdatatranslation; ' ; SELECT * FROM LO ...
- Page Visibility(网页可见性) API与登录同步引导页实例页面
页面1 HTML代码: <p id="loginInfo"></p> JS代码: (function() { if (typeof pageVis ...
- linux之重定向命令
1.shell重定向概念:shell重定向包含输出重定向和输入重定向 何为输入输出方向?何为标准输入输出方向? 标准输入方向:从键盘读取用户输入的数据,然后再把数据拿到程序(C语言程序.Shell 脚 ...
- java_22.1 Map 的应用
定义一个九年级,年级里面有一班和二班.且有属于自己班的学生. 九年级 一班 001 张三 002 李四 二班 001 王五 002 马六 把同学都遍历出来 package demo; import ...
- maven 监理web war 项目