自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

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

原创 Leetcode 58 - Length of Last Word

Given a string s consists of upper/lower-case alphabets and empty space characters ’ ‘, return the length of last word in the string.If the last word does not exist, return 0.Note: A word is defined as

2016-02-01 08:23:57 244

原创 Leetcode 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 are

2016-02-01 08:01:22 251

原创 Leetcode 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

2016-02-01 07:27:59 266

原创 Leetcode 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?class Solution {public: void rotate(vector<vector<int>>& ma

2016-01-27 07:50:46 240

原创 Leetcode 50 - Pow(x, n)

Implement pow(x, n).class Solution {public: double myPow(double x, int n) { if(n == 0) return 1; //注意n==INT_MIN的时候会溢出,-n仍然会等于INT_MIN if(n<0 && n!=INT_MIN) return 1.0/myPow(

2016-01-27 07:41:20 243

原创 Leetcode 46 - Permutations

Given a collection of distinct numbers, return all possible permutations.For example, [1,2,3] have the following permutations: [1,2,3], [1,3,2], [2,1,3], [2,3,1], [3,1,2], and [3,2,1].思路:深度优先搜索。class

2016-01-27 03:09:50 259

原创 Leetcode 41 - First Missing Positive

Given an unsorted integer array, find the first missing positive integer.For example, Given [1,2,0] return 3, and [3,4,-1,1] return 2.Your algorithm should run in O(n) time and uses constant space.cl

2016-01-27 02:31:05 180

原创 Leetcode 40 - Combination Sum II

Given a collection of candidate numbers (C) and a target number (T), find all unique combinations in C where the candidate numbers sums to T.Each number in C may only be used once in the combination.No

2016-01-25 08:38:26 197

原创 Leetcode 39 - Combination Sum

Given a set of candidate numbers (C) and a target number (T), find all unique combinations in C where the candidate numbers sums to T.The same repeated number may be chosen from C unlimited number of t

2016-01-25 07:54:49 247

原创 Leetcode 38 - Count and Say

The count-and-say sequence is the sequence of integers beginning as follows: 1, 11, 21, 1211, 111221, …1 is read off as “one 1” or 11. 11 is read off as “two 1s” or 21. 21 is read off as “one 2, the

2016-01-25 07:05:54 212

原创 Leetcode 36 - Valid Sudoku

Determine if a Sudoku is valid, according to: Sudoku Puzzles - The Rules.The Sudoku board could be partially filled, where empty cells are filled with the character ‘.’. class Solution {public: b

2016-01-24 13:08:59 373

原创 Leetcode 35 - Search Insert Position

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.Here

2016-01-24 12:43:32 206

原创 Leetcode 34 - Search for a Range

Given a sorted array of integers, find the starting and ending position of a given target value.Your algorithm’s runtime complexity must be in the order of O(log n).If the target is not found in the ar

2016-01-24 12:15:01 178

原创 Leetcode 32 - Longest Valid Parentheses

Given a string containing just the characters ‘(’ and ‘)’, find the length of the longest valid (well-formed) parentheses substring.For “(()”, the longest valid parentheses substring is “()”, which has

2016-01-23 06:09:24 204

原创 Leetcode 29 - Divide Two Integers

Divide two integers without using multiplication, division and mod operator.If it is overflow, return MAX_INT.1 - 细节实现题。题目要求不使用乘法、除法和取模,还么还可以使用加法,减法和位运算。 2 - 最简单的方法,是不断减去被除数。 3 - 在这个基础上,可以做一点优化,每次把被除

2016-01-23 04:22:50 219

原创 Leetcode 27 - 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.1 - 思路与Lee

2016-01-22 12:17:05 287

原创 Leetcode 26 - Remove Duplicates from Sorted Array

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

2016-01-21 08:14:46 178

原创 Leetcode 24 - Swap Nodes in Pairs

Given a linked list, swap every two adjacent nodes and return its head.For example, Given 1->2->3->4, you should return the list as 2->1->4->3.Your algorithm should use only constant space. You may no

2016-01-21 07:44:58 149

原创 Leetcode 22 - Generate Parentheses

Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses.For example, given n = 3, a solution set is:“((()))”, “(()())”, “(())()”, “()(())”, “()()()”1 - 可以

2016-01-21 07:02:57 205

原创 Leetcode 21 - Merge Two Sorted Lists

Merge two sorted linked lists and return it as a new list. The new list should be made by splicing together the nodes of the first two lists.1 - 简单的链表操作 2 - 应该注意到,题目要求新的链表应该由两个旧链表接合而成。因此,我们应该仅仅修改指针,而不

2016-01-21 06:33:11 137

原创 Leetcode 20 - Valid Parentheses

Given a string containing just the characters ‘(‘, ‘)’, ‘{‘, ‘}’, ‘[’ and ‘]’, determine if the input string is valid.The brackets must close in the correct order, “()” and “()[]{}” are all valid but “

2016-01-21 06:19:26 192

原创 Leetcode 18 - 4Sum

Given an array S of n integers, are there elements a, b, c, and d in S such that a + b + c + d = target? Find all unique quadruplets in the array which gives the sum of target.Note: Elements in a quad

2016-01-21 06:11:33 155

原创 Leetcode 19 - 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,Given linked list: 1->2->3->4->5, and n = 2.After removing the second node from the end, the linked list be

2016-01-15 09:08:26 146

原创 Leetcode 17 - Letter Combinations of a Phone Number

Given a digit string, return all possible letter combinations that the number could represent.A mapping of digit to letters (just like on the telephone buttons) is given below. 1 - 深度优先搜索,采用递归实现。class

2016-01-11 22:51:10 194

原创 Leetcode 16 - 3Sum Closest

Given an array S of n integers, find three integers in S such that the sum is closest to a given number, target. Return the sum of the three integers. You may assume that each input would have exactly

2016-01-11 17:52:42 127

原创 Leetcode 14 - Longest Common Prefix

Write a function to find the longest common prefix string amongst an array of strings.只需要将每个字符串逐一和第一个字符串(即strs[0])比较,一旦发现不相同的则停止比较。class Solution {public: string longestCommonPrefix(vector<string>

2016-01-11 16:30:10 184

原创 Leetcode 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.例子:遇到类似IV的数字,扫描到V时,发现V比I大,将最终结果加上V时,应当减去2倍的I。class Solution {public: int romanToInt(string

2016-01-11 16:09:15 149

原创 Leetcode 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

2016-01-11 12:45:09 160

原创 Leetcode 10 - Regular Expression Matching

Implement regular expression matching with support for ‘.’ and ‘*’.‘.’ Matches any single character. ‘*’ Matches zero or more of the preceding element.The matching should cover the entire input string

2016-01-11 11:42:57 182

原创 Leetcode 9 - Palindrome Number

Determine whether an integer is a palindrome. Do this without extra space.Some hints: Could negative integers be palindromes? (ie, -1)If you are thinking of converting the integer to string, note the

2015-12-24 22:59:36 189

原创 Leetcode 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

2015-12-24 22:25:13 188

原创 Leetcode 7 - Reverse Integer

Reverse digits of an integer.Example1: x = 123, return 321 Example2: x = -123, return -321Have you thought about this? Here are some good questions to ask before coding. Bonus points for you if you h

2015-12-24 21:48:27 183

原创 Leetcode 5 - Longest Palindromic Substring

Given a string S, find the longest palindromic substring in S. You may assume that the maximum length of S is 1000, and there exists one unique longest palindromic substring.1 - 简单的动态规划。class Solution

2015-12-21 18:02:13 275

原创 Leetcode 3 - Longest Substring Without Repeating Characters

Given a string, find the length of the longest substring without repeating characters. For example, the longest substring without repeating letters for “abcabcbb” is “abc”, which the length is 3. For “

2015-12-21 17:08:39 209

原创 Leetcode 2 - Add Two Numbers

1 - 简单的链表操作 2 - 活用三元表达式简化代码class Solution {public: ListNode* addTwoNumbers(ListNode* l1, ListNode* l2) { ListNode dummy(-1); ListNode *cur = &dummy; int carry = 0;

2015-12-21 12:26:08 270

原创 Leetcode 1 - Two Sum

class Solution {public: vector<int> twoSum(vector<int>& nums, int target) { vector<int> result; unordered_map<int,int> map; for(int i=0;i<nums.size();i++){ map[

2015-12-21 11:56:49 243

空空如也

空空如也

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

TA关注的人

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