自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(6)
  • 收藏
  • 关注

原创 1. Two Sum

不用暴力求解,用O(n)的复杂度需要利用map。class Solution { public: vector<int> twoSum(vector<int>& nums, int target) { vector<int > x(2); int t; unordered_map<int,int&gt...

2018-04-19 14:56:59 92

原创 219 Contains Duplicate II

第一次做与map容器有关的练习,花了点时间学习了map的一些用法。1、map是一个映射容器。2、map当中有许多用法,例如count返回是否存在key对应的数据。class Solution { public: bool containsNearbyDuplicate(vector<int>& nums, int k) { unordered_map<in...

2018-04-19 13:52:45 76

原创 169. Majority Element(关于摩尔投票法)

Given an array of size n, find the majority element. The majority element is the element that appears more than ⌊ n/2 ⌋ times.You may assume that the array is non-empty and the majority element always...

2018-04-10 09:51:56 147

原创 53. Maximum Subarray

Find the contiguous subarray within an array (containing at least one number) which has the largest sum.For example, given the array [-2,1,-3,4,-1,2,1,-5,4],the contiguous subarray [4,-1,2,1] has the ...

2018-04-09 10:10:16 64

原创 18. Pascal's Triangle

天真的以为需要格式空格等等都要注意:class Solution { public: vector<vector<int>> generate(int numRows) { vector<vector<int>> a; a.resize(numRows); for(int i=0;i<nu...

2018-04-03 13:34:41 71

转载 利用“异或”处理数组的相关算法的几个例子

例1,寻找数组中丢失的数。。。 有一组数字,从1到n减少了一个数,顺序也被打乱了,放在一个n-1的数组里,请找出丢失的数字。 在上一篇“数组公式相关算法”里介绍过一些解法,不过,那样解的话,可能会有溢出的危险。我们可以利用位运算中的“异或” 来巧妙解决这个问题。 算法步骤:1,对1-n个数做异或运算,得到XOR = 1^2^3^4….^n。 2, 用XOR与当前n-1数组的所有元素依次取异或: 因...

2018-04-03 10:00:02 952

空空如也

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除