【LeetCode OJ】Remove Element
题目:Given an array and a value, remove all instances of that value in place and return the new length.
The order of elements can be changed. It doesn't matter what you leave beyond the new length.
代码:
class Solution
{
public:
int removeElement(int A[], int n, int elem)
{
for (int i = ; i < n; ++i)
{
if (A[i] == elem)
{
for (int j = i; j < n; ++j)
{
A[j] = A[j+];
}
n--;
i--;
}
}
return n;
}
};
【LeetCode OJ】Remove Element的更多相关文章
- 【LeetCode OJ】Remove Duplicates from Sorted Array
题目:Given a sorted array, remove the duplicates in place such that each element appear only once and ...
- 【LeetCode OJ】Remove Nth Node From End of List
题目:Given a linked list, remove the nth node from the end of list and return its head. For example: G ...
- 【LeetCode OJ】Majority Element
题目:Given an array of size n, find the majority element. The majority element is the element that app ...
- 【LeetCode 229】Majority Element II
Given an integer array of size n, find all elements that appear more than ⌊ n/3 ⌋ times. The algorit ...
- 【LeetCode OJ】Interleaving String
Problem Link: http://oj.leetcode.com/problems/interleaving-string/ Given s1, s2, s3, find whether s3 ...
- 【LeetCode OJ】Reverse Words in a String
Problem link: http://oj.leetcode.com/problems/reverse-words-in-a-string/ Given an input string, reve ...
- 【LeetCode OJ】Pascal's Triangle II
Problem Link: http://oj.leetcode.com/problems/pascals-triangle-ii/ Let T[i][j] be the j-th element o ...
- 【LeetCode OJ】Triangle
Problem Link: http://oj.leetcode.com/problems/triangle/ Let R[][] be a 2D array where R[i][j] (j < ...
- 【LeetCode OJ】Longest Consecutive Sequence
Problem Link: http://oj.leetcode.com/problems/longest-consecutive-sequence/ This problem is a classi ...
随机推荐
- SAP财务供应链与金库管理的联系与区别
SAP Treasure Module & Cash Fund , Risk Management 本文简要阐述一下什么是财务供应链管理(FSCM),什么是金库管理(Treasury Ma ...
- Build opencv libraries for android arm, x86 ubuntu
废话不多说. 准备工作: 1. 下载源代码: http://opencv.org/ 编译平台:ubuntu14.04 opencv 2.4.6.1 本人用这样的办法编译了opecv 2.4.9 的没有 ...
- HTML5 3D爱心动画及其制作过程
之前有看到过很多基于HTML5或者CSS3制作的爱心动画,不过基本上都是2D平面的,今天在国外的网站上看到一个基于HTML5 3D的爱心动画,对于HTML5爱好者来说,不免兴奋了一把.下面将分享一下这 ...
- php base64_encode,serialize对于存入数据表中字段的数据处理方案
A better way to save to Database $toDatabse = base64_encode(serialize($data)); // Save to database $ ...
- result源码
CREATE TABLE `result` (`id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,`thetime` CHAR(100) , `category ...
- Objective-C语法之指针型参数
main.m #import <Foundation/Foundation.h> /** * 测试指针型参数和普通参数的区别 * * @param a 指针型参数 * @param b 普 ...
- Deep Voice
https://arxiv.org/abs/1702.07825 听起来和真人声非常接近了.
- Java 11正式发布,这几个逆天新特性教你写出更牛逼的代码
就在前段时间,Oracle 官方宣布 Java 11 (18.9 LTS) 正式发布,可在生产环境中使用! 这无疑对我们来说是一大好的消息.作为一名java开发者来说,虽然又要去学习和了解java11 ...
- python 使用循环生成list
#-*- coding:UTF-8 -*- squares=[] for x in range(10): squares.append(x**2) print squares #[0, 1, 4, 9 ...
- Ubuntu18.10下安装Qt5.12过程记录
首先你得先安装Ubuntu操作系统(我是在VMWare14中安装的Ubuntu18.10版本). 阿里镜像:https://opsx.alibaba.com/mirror 我这里下载的文件为:ubun ...