自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

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

原创 15. 3Sum,16. 3Sum Closest,18. 4Sum(最后一个方法重要)重要

第一题、15. 3Sum Given an array S of n integers, are there elements a, b, c in S such that a + b + c = 0? Find all unique triplets in the array which gives the sum of zero.Note: The solution set must not

2017-02-28 18:38:27 934

原创 26. Remove Duplicates from Sorted Array and 80. Remove Duplicates from Sorted Array II

Given a sorted array, remove the duplicates in place such that each element appear only once and return the new length.Do not allocate extra space for another array, you must do this in place with cons

2017-02-23 19:21:40 231

原创 75. Sort Colors--荷兰三色国旗问题

Given an array with n objects colored red, white or blue, sort them so that objects of the same color are adjacent, with the colors in the order red, white and blue.Here, we will use the integers 0, 1,

2017-02-23 18:55:48 511

原创 78. Subsets ,90. Subsets II(待研究)---位运算法(重要和Combination Sum一系列的题目类似)

第一题、78. Subsets Given a set of distinct integers, nums, return all possible subsets. Note: The solution set must not contain duplicate subsets. For example, If nums = [1,2,3], a solution is: [ ...

2017-02-23 15:35:21 386

转载 152. Maximum Product Subarray Add to List --- 注意

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

2017-02-18 11:08:07 567

原创 发现一个数组中重复的数字,448和287的总结 ---重要

区别一、448题目没有限制不能改变原来的数组,所以采用的是交换机制,不断的将错误位置上的数据不断的交换移动到本该属于其的位置上去,则重新遍历时,nums[i]!=i+1的数字即没有出现的数字,但287题目则限制了不能改变原来的数组,所以不能采用交换机制的方法,方法类似采用查找循环链表的环入口的方法,或者可以采用利用二分查找的思想; 区别二、448题目中1-n之间重复的数字只出现了两次,但是在287

2017-02-17 13:39:34 911

原创 Combination Sum系列的三个题目39,40,216--重要(和78. Subsets ,90. Subsets II类似)

Combination Sum Given a set of candidate numbers (C) (without duplicates) and a target number (T), find all unique combinations in C where the candidate numbers sums to T. The same repeated number ma

2017-02-17 13:08:30 414

原创 219. Contains Duplicate II---数组中两个重复的数字的下标最多相差k

Given an array of integers and an integer k, find out whether there are two distinct indices i and j in the array such that nums[i] = nums[j] and the absolute difference between i and j is at most k.

2017-02-17 10:46:31 692

原创 217. Contains Duplicate

Given an array of integers, find if the array contains any duplicates. Your function should return true if any value appears at least twice in the array, and it should return false if every element is

2017-02-17 10:30:59 276

原创 1. Two Sum,167. Two Sum II - Input array is sorted

Given an array of integers that is already sorted in ascending order, find two numbers such that they add up to a specific target number.The function twoSum should return indices of the two numbers suc

2017-02-13 18:07:01 313

转载 c++中map与unordered_map的区别

c++中map与unordered_map的区别头文件map: #include unordered_map: #include 内部实现机理map: map内部实现了一个红黑树,该结构具有自动排序的功能,因此map内部的所有元素都是有序的,红黑树的每一个节点都代表着map的一个元素,因此,对于map进行的查找,删除,添加等一系列的操作都相当于是对红黑树进行这样的操

2017-02-28 21:57:16 598

原创 13. Roman to Integer

第一题、13. Roman to Integer Given a roman numeral, convert it to an integer. Input is guaranteed to be within the range from 1 to 3999. 解题思路: 罗马数字是符号和加操作的一个组合。他基于以下七个符号。 II is 2, and XIII is 13. 罗马

2017-02-28 21:49:05 231

原创 383. Ransom Note--哈希的方法

Given an arbitrary ransom note string and another string containing letters from all the magazines, write a function that will return true if the ransom note can be constructed from the magazines ; oth

2017-02-28 20:45:08 336

原创 520. Detect Capital

Given a word, you need to judge whether the usage of capitals in it is right or not. We define the usage of capitals in a word to be right when one of the following cases holds: All letters in this w

2017-02-28 20:34:58 291

原创 151. Reverse Words in a String

Given an input string, reverse the string word by word. For example, Given s = “the sky is blue”, return “blue is sky the”. Update (2015-02-12): For C programmers: Try to solve it in-place in O(1)

2017-02-28 20:09:14 281

转载 C++ vector 的resize和reverve

1、resize(n) 调整容器的长度大小,使其能容纳n个元素。如果n小于容器的当前的size,则删除多出来的元素。否则,添加采用值初始化的元素。2、 resize(n,t)多一个参数t,将所有新添加的元素初始化为t。而reserver()的用法只有一种reserve(n)预分配n个元素的存储空间。了解这两个函数的区别,首先要

2017-02-28 20:06:42 720

转载 55. Jump Game

Given an array of non-negative integers, you are initially positioned at the first index of the array. Each element in the array represents your maximum jump length at that position. Determine if you

2017-02-28 19:05:42 173

原创 88. Merge Sorted Array

Given two sorted integer arrays nums1 and nums2, merge nums2 into nums1 as one sorted array.Note: You may assume that nums1 has enough space (size that is greater or equal to m + n) to hold additional

2017-02-28 18:20:36 229

原创 120. Triangle

Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjacent numbers on the row below.For example, given the following triangle [ [2], [3,4], [6,5,

2017-02-28 17:38:35 235

原创 73. Set Matrix Zeroes

Given a m x n matrix, if an element is 0, set its entire row and column to 0. Do it in place 方法一: 本算法的时间复杂度为O(m*n),空间复杂度为:O(m+n) 思想:首先遍历一边数组将数组中出现0的那一行以及那一列出现了的行号和列号记录在record(record初始化为0)中;再依次遍历一边re

2017-02-28 16:22:03 408

原创 8. String to Integer (atoi) --重要

Implement atoi to convert a string to an integer.Hint: Carefully consider all possible input cases. If you want a challenge, please do not see below and ask yourself what are the possible input cases.N

2017-02-27 21:17:55 231

原创 345. Reverse Vowels of a String

Write a function that takes a string as input and reverse only the vowels of a string.Example 1: Given s = “hello”, return “holle”.Example 2: Given s = “leetcode”, return “leotcede”.Note: The vowels

2017-02-27 20:20:32 211

原创 344. Reverse String

Write a function that takes a string as input and returns the string reversed.Example: Given s = “hello”, return “olleh”.string reverseString(string s) { int j = s.size() - 1; int i =

2017-02-27 20:09:08 265

转载 欠拟合、过拟合及其解决方法

在我们机器学习或者训练深度神经网络的时候经常会出现欠拟合和过拟合这两个问题,但是,一开始我们的模型往往是欠拟合的,也正是因为如此才有了优化的空间,我们需要不断的调整算法来使得模型的表达能拿更强。但是优化到了一定程度就需要解决过拟合的问题了,这个问题也在学术界讨论的比较多。(之前搜了很多有的博客,讲的都不太全,因此我重新整理总结了一遍,同时加入了自己的理解,方便自己和后来人查阅)

2017-02-26 15:32:36 2429 1

转载 413. Arithmetic Slices(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 sequenc

2017-02-24 19:08:25 264

原创 338. Counting Bits 和191. Number of 1 Bits

Given a non negative integer number num. For every numbers i in the range 0 ≤ i ≤ num calculate the number of 1’s in their binary representation and return them as an array.Example: For num = 5 you sh

2017-02-24 18:36:29 306

原创 162. Find Peak Element

A peak element is an element that is greater than its neighbors.Given an input array where num[i] ≠ num[i+1], find a peak element and return its index.The array may contain multiple peaks, in that case

2017-02-23 19:27:36 284

原创 11. Container With Most Water

Given n non-negative integers a1, a2, …, an, where each represents a point at coordinate (i, ai). n vertical lines are drawn such that the two endpoints of line i is at (i, ai) and (i, 0). Find two lin

2017-02-23 19:14:56 216

原创 118. Pascal's Triangle

Given numRows, generate the first numRows of Pascal’s triangle.For example, given numRows = 5, Return[ [1], [1,1], [1,2,1], [1,3,3,1], [1,4,6,4,1] ] 方法一、vector<vector<int> > gene

2017-02-23 18:35:03 195

原创 66. Plus One

Given a non-negative integer represented as a non-empty array of digits, plus one to the integer.You may assume the integer do not contain any leading zero, except the number 0 itself.The digits are st

2017-02-23 18:31:50 389

原创 48. Rotate Image--重点看思路三

You are given an n x n 2D matrix representing an image.Rotate the image by 90 degrees (clockwise).Follow up:Could you do this in-place?着重注意思路三【题意】给定一个n*n个2维矩阵来表示一个图。在原矩阵上旋转图形90°。

2017-02-23 17:47:56 1264

原创 27. Remove Element

Given an array and a value, 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 in place with constant memory.The order

2017-02-23 16:58:06 304

原创 380. Insert Delete GetRandom O(1)--构造新类的题目

Design a data structure that supports all following operations in average O(1) time.insert(val): Inserts an item val to the set if not already present. remove(val): Removes an item val from the set if

2017-02-23 16:45:32 327

转载 emplace_back() 和 push_back 的区别

在引入右值引用,转移构造函数,转移复制运算符之前,通常使用push_back()向容器中加入一个右值元素(临时对象)的时候,首先会调用构造函数构造这个临时对象,然后需要调用拷贝构造函数将这个临时对象放入容器中。原来的临时变量释放。这样造成的问题是临时变量申请的资源就浪费。 引入了右值引用,转移构造函数(请看这里)后,push_back()右值时就会调用构造函数和转移构造函数。 在这上面有进一

2017-02-23 16:29:08 327

原创 64. Minimum Path Sum

Given a m x n grid filled with non-negative numbers, find a path from top left to bottom right which minimizes the sum of all numbers along its path.Note: You can only move either down or right at any

2017-02-23 16:02:03 400

原创 54. Spiral Matrix (有待进一步研究)

Given a matrix of m x n elements (m rows, n columns), return all elements of the matrix in spiral order.For example, Given the following matrix:[ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ] You sh

2017-02-23 13:10:01 304

原创 new/delete和malloc/free的关系

1.共同点 都可用于动态申请系统的内存; 2.区别 (1)new/delete是c++的运算符,malloc/free是库函数,不是运算符; (2)new会自动执行构造函数,能满足c++语言动态内存分配和初始化工作,delete会自动执行析构函数,能完成c++语言中的清理与释放内存的工作;对于非内部数据结构(诸如类的实例)而言,光用malloc/free无法满足动态对象的要求(由于mallo

2017-02-23 12:27:46 564

原创 59. Spiral Matrix II(待进一步研究)

Given an integer n, generate a square matrix filled with elements from 1 to n2 in spiral order.For example, Given n = 3,You should return the following matrix: [ [ 1, 2, 3 ], [ 8, 9, 4 ], [ 7,

2017-02-23 11:15:32 308

原创 53. Maximum Subarray Add to List

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

2017-02-18 10:52:06 547

原创 62. Unique Paths 和63. Unique Paths II

一、62. Unique Paths A robot is located at the top-left corner of a m x n grid (marked ‘Start’ in the diagram below). The robot can only move either down or right at any point in time. The robot is try

2017-02-17 17:28:29 387

空空如也

空空如也

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

TA关注的人

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