2017/11/22 Leetcode 日记

136. Single Number

Given an array of integers, every element appears twice except for one. Find that single one.

class Solution {
public:
int singleNumber(vector<int>& nums) {
int len = nums.size();
int a = nums[];
for(int i = ; i < len; i++){
a ^= nums[i];
// cout<<a<<endl;
}
return a;
}
};

C++

413. Arithmetic Slices

A sequence of number is called arithmetic if it consists of at least three elements and if the difference between any two consecutive elements is the same.

For example, these are arithmetic sequence:

1, 3, 5, 7, 9
7, 7, 7, 7
3, -1, -5, -9

The following sequence is not arithmetic.

1, 1, 2, 5, 7

A zero-indexed array A consisting of N numbers is given. A slice of that array is any pair of integers (P, Q) such that 0 <= P < Q < N.

A slice (P, Q) of array A is called arithmetic if the sequence:
A[P], A[p + 1], ..., A[Q - 1], A[Q] is arithmetic. In particular, this means that P + 1 < Q.

The function should return the number of arithmetic slices in the array A.

class Solution {
// 2nd round date: 2016-10-15 location: Vista Del Lago III Apartement
public:
int numberOfArithmeticSlices(vector<int>& A) {
if (A.size() < ) return ;
vector<int> dp(A.size(), );
int res = ;
for (int i = ; i < A.size(); i ++) {
if (A[i] - A[i - ] == A[i - ] - A[i - ])
dp[i] = dp[i - ] + ;
res += dp[i];
}
return res;
}
};

c++

2017/11/22 Leetcode 日记的更多相关文章

  1. 2017/11/21 Leetcode 日记

    2017/11/21 Leetcode 日记 496. Next Greater Element I You are given two arrays (without duplicates) num ...

  2. 2017/11/13 Leetcode 日记

    2017/11/13 Leetcode 日记 463. Island Perimeter You are given a map in form of a two-dimensional intege ...

  3. 2017/11/20 Leetcode 日记

    2017/11/14 Leetcode 日记 442. Find All Duplicates in an Array Given an array of integers, 1 ≤ a[i] ≤ n ...

  4. 2017/11/9 Leetcode 日记

    2017/11/9 Leetcode 日记 566. Reshape the Matrix In MATLAB, there is a very useful function called 'res ...

  5. 2017/11/7 Leetcode 日记

    2017/11/7 Leetcode 日记 669. Trim a Binary Search Tree Given a binary search tree and the lowest and h ...

  6. 2017/11/6 Leetcode 日记

    2017/11/6 Leetcode 日记 344. Reverse String Write a function that takes a string as input and returns ...

  7. 2017/11/5 Leetcode 日记

    2017/11/5 Leetcode 日记 476. Number Complement Given a positive integer, output its complement number. ...

  8. 2017/11/3 Leetcode 日记

    2017/11/3 Leetcode 日记 654. Maximum Binary Tree Given an integer array with no duplicates. A maximum ...

  9. 2017.11.22 mysql数据库实现关联表更新sql语句

    比如有两张表,其中一张表某个字段的值要关联另一张表进行统计,就要用到mysql的update方法,并且left join另一张表进行联合查询. mysql关联表更新统计 sql语句如下: 代码如下 复 ...

随机推荐

  1. 一般处理程序、ASP.NET核心知识(5)

    初窥 1.新建一个一般处理程序 新建一个一般处理程序 2.看看里头的代码 public class MyHandler : IHttpHandler { public void ProcessRequ ...

  2. SQL Server 高级SQL

    查询view 的列和列数据类型 SELECT COLUMN_NAME, DATA_TYPE FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'vi ...

  3. BestCoder Round92

    题目链接:传送门 HDU 6015-6018 解题报告:传送门 HDU6015 Skip the Class  Accepts: 678  Submissions: 1285  Time Limit: ...

  4. 原创:HTML 头像截取上传 JS+PHP 整合包~

    关于: 关于头像上传这个东西,网上一搜乱七八糟的一堆然而很少很少有自己中意的插件一怒之下就自己写一个... 用法: <!DOCTYPE html> <html lang=" ...

  5. Go语言 2 变量、常量和数据类型

    文章由作者马志国在博客园的原创,若转载请于明显处标记出处:http://www.cnblogs.com/mazg/ Go学习群:415660935 2.1 变量 变量是对一块内存空间的命名,程序可以通 ...

  6. nginx证书制作以及配置https并设置访问http自动跳转https(反向代理转发jboss)

    nginx证书制作以及配置https并设置访问http自动跳转https 默认情况下ssl模块并未被安装,如果要使用该模块则需要在编译时指定–with-http_ssl_module参数,安装模块依赖 ...

  7. 26_Python的内置函数

    The Python interpreter has a number of functions and types built into it that are always available.P ...

  8. cordova 从xcode7迁移到xcode8

    环境以开发流程 当前项目使用的cordova环境 cordova 6.1.1 cordova-ios 3.9.2(vs15自动装的不知道在哪能改,所以考虑升级到vs17,能够手动指定) cordova ...

  9. vsftpd.log内容的意义

    vsftpd日志(xferlog格式)的含义 引用: Thu Mar 4 08:12:30 2004 1 202.114.40.242 37 /incoming/index.html a _ o a  ...

  10. hdu 1907(Nim博弈)

    John Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)Total Submis ...