1   Remove Element    lintcode-172

描述: 删相同元素,反现有长度

记忆:标不同元素,反标记值

  public int removeElement(int[] a, int elem) {
// write your code here
int index = 0;
for (int i = 0; i < a.length; i++) {
if (a[i] != elem) {
a[index++] = a[i];
}
}
return index;
}

2 Remove Duplicates from Sorted Array 1    lintCode-100

描述:已排序,删相同,反长度

记忆:标记不同元素,反标记

 public int removeDuplicates(int[] nums) {
// write your code here
if (nums.length == 0) {
return 0;
}
int index = 0;
for (int i = 1; i < nums.length; i++) {
if (nums[index] != nums[i]) {
nums[++index] = nums[i];
}
}
return index + 1;
}

3 Remove Duplicates from Sorted Array 2    lintCode-101

描述:已排序,删,最多两,反长度

记忆:加标记,不等标记少二,才加长

     public int removeDuplicates(int[] nums) {
// write your code here
if (nums.length < 2) {
return nums.length;
}
int index = 2;
for (int i = 2; i < nums.length; i++) {
if (nums[i] != nums[index - 2]) {
nums[index++] = nums[i];
}
}
return index;
}
}

4 Plus One   lintCode-407

描述:数组加一反数组

记忆:加一,进位

  public int[] plusOne(int[] digits) {
// Write your code here
int carries = 1;
for (int i = digits.length - 1; i >= 0 && carries > 0; i--) {
int sum = digits[i] + carries;
digits[i] = sum % 10;
carries = sum / 10;
} if (carries == 0) {
return digits;
} int[] rst = new int[digits.length + 1];
rst[0] = 1;
for (int i = 1; i < rst.length; i++) {
rst[i] = digits[i - 1];
} return rst;
}

5 Pascal's Triangle  杨辉三角

记忆:两数组链表,分类

 public static List<Integer> row(int rowIndex) {
List<Integer> res = new ArrayList<Integer>();
int temp = 1;
for (int i = 1; i <= rowIndex; i++) {
List<Integer> list = new ArrayList<Integer>();
if (i == 1) {
list.add(0, 1);
} else if (i == 2) {
list.add(0, 1);
list.add(1, 1);
} else {
list.add(0, 1);
for (int k = 0; k < res.size() - 1; k++) {
int sum = res.get(k) + res.get(k + 1);
list.add(sum);
}
list.add(i - 1, 1);
}
res = list;
}
System.out.println(res);
return res;
}

lettCode-Array的更多相关文章

  1. Lettcode Kth Largest Element in an Array

    Lettcode Kth Largest Element in an Array 题意:在无序数组中,寻找第k大的数字,注意这里考虑是重复的. 一直只会简单的O(nlogn)的做法,听说这题有O(n) ...

  2. javascript中的Array对象 —— 数组的合并、转换、迭代、排序、堆栈

    Array 是javascript中经常用到的数据类型.javascript 的数组其他语言中数组的最大的区别是其每个数组项都可以保存任何类型的数据.本文主要讨论javascript中数组的声明.转换 ...

  3. ES5对Array增强的9个API

    为了更方便的对Array进行操作,ES5规范在Array的原型上新增了9个方法,分别是forEach.filter.map.reduce.reduceRight.some.every.indexOf ...

  4. JavaScript Array对象

    介绍Js的Array 数组对象. 目录 1. 介绍:介绍 Array 数组对象的说明.定义方式以及属性. 2. 实例方法:介绍 Array 对象的实例方法:concat.every.filter.fo ...

  5. 了解PHP中的Array数组和foreach

    1. 了解数组 PHP 中的数组实际上是一个有序映射.映射是一种把 values 关联到 keys 的类型.详细的解释可参见:PHP.net中的Array数组    . 2.例子:一般的数组 这里,我 ...

  6. 关于面试题 Array.indexof() 方法的实现及思考

    这是我在面试大公司时碰到的一个笔试题,当时自己云里雾里的胡写了一番,回头也曾思考过,最终没实现也就不了了之了. 昨天看到有网友说面试中也碰到过这个问题,我就重新思考了这个问题的实现方法. 对于想进大公 ...

  7. javascript之活灵活现的Array

    前言 就如同标题一样,这篇文章将会灵活的运行Array对象的一些方法来实现看上去较复杂的应用. 大家都知道Array实例有这四个方法:push.pop.shift.unshift.大家也都知道 pus ...

  8. 5.2 Array类型的方法汇总

    所有对象都具有toString(),toLocaleString(),valueOf()方法. 1.数组转化为字符串 toString(),toLocaleString() ,数组调用这些方法,则返回 ...

  9. OpenGL ES: Array Texture初体验

    [TOC] Array Texture这个东西的意思是,一个纹理对象,可以存储不止一张图片信息,就是说是是一个数组,每个元素都是一张图片.这样免了频繁地去切换当前需要bind的纹理,而且可以节省系统资 ...

  10. Merge Sorted Array

    Given two sorted integer arrays nums1 and nums2, merge nums2 into nums1 as one sorted array. Note:Yo ...

随机推荐

  1. Decision Boundaries for Deep Learning and other Machine Learning classifiers

    Decision Boundaries for Deep Learning and other Machine Learning classifiers H2O, one of the leading ...

  2. 对于 APM 用户的一次真实调查分析(下)

    一.前言 对 APM 用户的一次真实调查分析(上)中,我们主要聊到了现阶段国外 APM 行业对各个企业的渗透率.大部分使用 APM 工具的企业规模以及 APM 工具在用户心中的地位等问题,有兴趣的朋友 ...

  3. 使用NSURLSession实现断点续传

    在sb中创建按钮,并且连线到.m文件中

  4. 手游:cocos2d-x3.0 移植 wp8 开发 各种 “蛋疼”问题的汇总

    蛋疼的问题的起源: wp8 做应用开发,显示显示中文,源码包含中文都是没有一点问题的, 只是cocos2d-x 的编码方式(UTF-8),引起的一系列的问题. 1:不能显示服务器返回的中文 2:c++ ...

  5. 定时显示提示控件 TToolTip

    转载过来的,文章出自: http://www.delphifans.com/infoview/Article_3640.html {    修改者:ghs    日期:20071218    功能:在 ...

  6. OpenSSL 与 SSL 数字证书概念贴

    SSL/TLS 介绍见文章 SSL/TLS原理详解(http://seanlook.com/2015/01/07/tls-ssl). 如果你想快速自建CA然后签发数字证书,请移步 基于OpenSSL自 ...

  7. RxJava开发精要4 – Observables过滤

    原文出自<RxJava Essentials> 原文作者 : Ivan Morgillo 译文出自 : 开发技术前线 www.devtf.cn 转载声明: 本译文已授权开发者头条享有独家转 ...

  8. leetcode面试准备:Reverse Words in a String

    leetcode面试准备:Reverse Words in a String 1 题目 Given an input string, reverse the string word by word. ...

  9. Layout Resource官方教程(3)在layout中用include嵌入其它layout

    简介 <include>Includes a layout file into this layout. 类似 #include ,把layout展开在include处 attribute ...

  10. 【原创】FPGA开发手记(一) UART接口

    以下内容均以Xilinx的Nexys3作为开发板 1. UART简介 UART(即Universal Asynchronous Receiver Transmitter 通用异步收发器)是广泛使用的串 ...