27. Remove Element (Easy)# 2019.7.7

Given an array nums and a value val, remove all instances of that value in-place and return the new length.

Do not allocate extra space for another array, you must do this by modifying the input array in-place with O(1) extra memory.

The order of elements can be changed. It doesn't matter what you leave beyond the new length.

Example 1:

Given nums = [3,2,2,3], val = 3,

Your function should return length = 2, with the first two elements of nums being 2.

It doesn't matter what you leave beyond the returned length.

Example 2:

Given nums = [0,1,2,2,3,0,4,2], val = 2,

Your function should return length = 5, with the first five elements of nums containing 0, 1, 3, 0, and 4.

Note that the order of those five elements can be arbitrary.

It doesn't matter what values are set beyond the returned length.

solution##

class Solution {
public int removeElement(int[] nums, int val) {
int newlength = 0;
for (int i = 0 ; i < nums.length; i++)
{
if (nums[i] != val)
nums[newlength++] = nums[i];
}
return newlength;
}
}

总结##

此题很水,没什么技术含量,不做过多解释!!

35. Search Insert Position (Easy)#2019.7.7

Given a sorted array and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in order.

You may assume no duplicates in the array.

Example 1:

Input: [1,3,5,6], 5
Output: 2
Example 2: Input: [1,3,5,6], 2
Output: 1
Example 3: Input: [1,3,5,6], 7
Output: 4
Example 4: Input: [1,3,5,6], 0
Output: 0

solution##

class Solution {
public int searchInsert(int[] nums, int target) {
for (int i = 0; i < nums.length; i++)
{
if (nums[i] >= target)
return i;
}
return nums.length;
}
}

总结##

此题很水,没什么技术含量,同样不做过多解释!!

LeetCode--Array--Remove Element && Search Insert Position(Easy)的更多相关文章

  1. [array] leetcode - 35. Search Insert Position - Easy

    leetcode - 35. Search Insert Position - Easy descrition Given a sorted array and a target value, ret ...

  2. LeetCode练题——35. Search Insert Position

    1.题目 35. Search Insert Position Easy 1781214Add to ListShare Given a sorted array and a target value ...

  3. Leetcode 题目整理 Sqrt && Search Insert Position

    Sqrt(x) Implement int sqrt(int x). Compute and return the square root of x. 注:这里的输入输出都是整数说明不会出现 sqrt ...

  4. LeetCode(35) Search Insert Position

    题目 Given a sorted array and a target value, return the index if the target is found. If not, return ...

  5. LeetCode记录之35——Search Insert Position

    这道题难度较低,没有必要作说明. Given a sorted array and a target value, return the index if the target is found. I ...

  6. LeetCode_35. Search Insert Position

    35. Search Insert Position Easy Given a sorted array and a target value, return the index if the tar ...

  7. [Leetcode][Python]35: Search Insert Position

    # -*- coding: utf8 -*-'''__author__ = 'dabay.wang@gmail.com' 35: Search Insert Positionhttps://oj.le ...

  8. 60. Search Insert Position 【easy】

    60. Search Insert Position [easy] Given a sorted array and a target value, return the index if the t ...

  9. LeetCode:Search Insert Position,Search for a Range (二分查找,lower_bound,upper_bound)

    Search Insert Position Given a sorted array and a target value, return the index if the target is fo ...

随机推荐

  1. shell脚本知识

    1.提示符变量PS1 修改提示符变量:PS1="[u\@\h \t \w]" 修改环境变量设置文件bash_profile需要使用source或者.加上该文件使之生效 位置参数从1 ...

  2. Mac 窗口管理软件 Spectacle

    我个人使用的窗口管理软件是 Magnet(本人在 Mac 下付费的首款软件,记得是 6 元~),今天为大家介绍一款类似的开源软件. 简介 Spectacle 是一款可以快速调整窗口大小与位置的开源软件 ...

  3. C++基础的一些代码和笔记 stl乱炖

    STL: 标准模板库.各种函数的模板和类的模板几个概念:容器:可容纳各种数据类型的通用数据结构,是类模板.迭代器:可用于依次存取容器中的元素,类似于指针,用iterator来进行对一个容器中单个元素的 ...

  4. Cobalt Stike使用教程

    目录: 安装与连接 监听器Listner 基本使用方法--Cobalt Strike生成后门 Beacon详解 菜单栏与视图 文件管理与进程管理 浏览器代理 Cobalt Strike扩展 提权 横向 ...

  5. 包、mode模式、if-else语句、switch语句

    目录 包 mode模式 if-else语句 循环 switch语句 包 //1 在同一个包下(文件夹下),包名必须一致 //2 以后,包名就是文件夹的名字 //3 同一个包下,同名函数只能有一个(in ...

  6. tensorflow版线性回归

    import os os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2' import tensorflow as tf def linearregression(): X ...

  7. 箭头函数的this指向问题-一看就懂

    OK,对于箭头函数的this 用一句话概括:箭头函数中的this指向的是定义时的this,而不是执行时的this. 如果上面这句话听的是懂非懂或者完全不懂的,没关系,下面会有案例讲解. 举个栗子 来看 ...

  8. C51_PID 水温控制系统

    C51_PID 水温控制系统 51CPIDUART水温控制 前言 通过C语言程序写入51单片机实现水的温度的采集,并通过控制器控制加热器给水体加热,对水体的温进行PID控制,保证温度在设定值范围内波动 ...

  9. 利用CRM实现电话营销部门的管控 之数据暂缓

    每个公司都有相应的电话营销部门,有的公司是使用的集中的Call Center,有的公司则是使用简单的销售软件.不同的公司都有各自运行管理的方法. 此篇文章主要是介绍基于微软Dynamic CRM下的自 ...

  10. 学会HTML就可以找工作了

    对编程小白来讲,想要学习门槛低,学习周期短,难度指数可忽略.短时间内可能找一份薪资不错编程相关工作,那就把HTML作为入门级语言吧. 网页设计师 (//upload-images.jianshu.io ...