
Cracking LeetCode
文章平均质量分 59
所难
这个作者很懒,什么都没留下…
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
LeetCode-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] ha原创 2014-08-13 22:50:56 · 312 阅读 · 0 评论 -
LeetCode-Pow(x, n)
Implement pow(x, n).Solution:Code:原创 2014-08-14 16:45:31 · 364 阅读 · 0 评论 -
LeetCode-Anagrams
Given an array of strings, return all groups of strings that are anagrams.Note: All inputs will be in lower-case.Solution:Code:原创 2014-08-14 21:26:32 · 318 阅读 · 0 评论 -
LeetCode-N-Queens
The n-queens puzzle is the problem of placing n queens on an n×n chessboard such that no two queens attack each other.Given an integer n, return all distinct solutions to the n-queens puzzle.原创 2014-08-14 16:28:36 · 329 阅读 · 0 评论 -
LeetCode-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?Solution:Code:class Solution {public: void原创 2014-08-14 21:51:53 · 347 阅读 · 0 评论 -
LeetCode-Permutations II
Given a collection of numbers that might contain duplicates, return all possible unique permutations.For example,[1,1,2] have the following unique permutations:[1,1,2], [1,2,1], and [2,1,1].原创 2014-08-15 12:23:42 · 367 阅读 · 0 评论 -
LeetCode-Jump Game II
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.Your goal i原创 2014-08-15 13:06:53 · 349 阅读 · 0 评论 -
LeetCode-Wildcard Matching
Implement wildcard pattern matching with support for '?' and '*'.'?' Matches any single character.'*' Matches any sequence of characters (including the empty sequence).The matching should cover t原创 2014-08-15 13:35:10 · 310 阅读 · 0 评论 -
LeetCode-Permutations
Given a collection of 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].Solution原创 2014-08-15 12:30:18 · 352 阅读 · 0 评论 -
LeetCode-Sudoku Solver
Write a program to solve a Sudoku puzzle by filling the empty cells.Empty cells are indicated by the character '.'.You may assume that there will be only one unique solution.A sudoku原创 2014-08-16 15:55:55 · 373 阅读 · 0 评论 -
LeetCode-Next Permutation
Implement next permutation, which rearranges numbers into the lexicographically next greater permutation of numbers.If such arrangement is not possible, it must rearrange it as the lowest possible原创 2014-08-17 14:48:00 · 348 阅读 · 0 评论 -
LeetCode-Implement strStr()
Implement strStr().Returns a pointer to the first occurrence of needle in haystack, or null if needle is not part of haystack.Solution:Code:原创 2014-08-17 18:44:38 · 311 阅读 · 0 评论 -
LeetCode-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原创 2014-08-17 19:09:30 · 290 阅读 · 0 评论 -
LeetCode-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原创 2014-08-16 17:11:50 · 380 阅读 · 0 评论 -
LeetCode-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 '.'.A partially fille原创 2014-08-16 16:07:51 · 299 阅读 · 0 评论 -
LeetCode-Search in Rotated Sorted Array
Suppose a sorted array is rotated at some pivot unknown to you beforehand.(i.e., 0 1 2 4 5 6 7 might become 4 5 6 7 0 1 2).You are given a target value to search. If found in the array retur原创 2014-08-16 22:22:12 · 493 阅读 · 0 评论 -
LeetCode-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.S原创 2014-08-17 19:03:41 · 314 阅读 · 0 评论 -
LeetCode-Substring with Concatenation of All Words
You are given a string, S, and a list of words, L, that are all of the same length. Find all starting indices of substring(s) in S that is a concatenation of each word in L exactly once and without an原创 2014-08-17 17:11:36 · 328 阅读 · 0 评论 -
LeetCode-Divide Two Integers
Divide two integers without using multiplication, division and mod operator.Solution:Code:原创 2014-08-17 17:29:40 · 411 阅读 · 0 评论 -
LeetCode-Climbing Stairs
You are climbing a stair case. It takes n steps to reach to the top.Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top?Solution:Code:原创 2014-08-10 21:29:52 · 332 阅读 · 0 评论 -
LeetCode-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.原创 2014-08-16 16:54:39 · 294 阅读 · 0 评论 -
LeetCode-Sqrt(x)
Implement int sqrt(int x).Compute and return the square root of x.Solution:Code:class Solution {public: int sqrt(int x) { if (x == 0) return 0; double last = 0;原创 2014-08-11 09:18:39 · 204 阅读 · 0 评论 -
LeetCode-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 "()",原创 2014-08-17 14:31:18 · 313 阅读 · 0 评论 -
LeetCode-Reverse Nodes in k-Group
Given a linked list, reverse the nodes of a linked list k at a time and return its modified list.If the number of nodes is not a multiple of k then left-out nodes in the end should remain as it is原创 2014-08-17 22:11:28 · 422 阅读 · 0 评论 -
LeetCode-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. Y原创 2014-08-17 22:27:14 · 275 阅读 · 0 评论 -
LeetCode-Merge k Sorted Lists
Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity.Solution:Code:原创 2014-08-17 22:59:19 · 315 阅读 · 0 评论 -
LeetCode-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:"((()))", "(()())", "(())()", "()(())", "()()原创 2014-08-18 11:13:33 · 288 阅读 · 0 评论 -
LeetCode-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 va原创 2014-08-18 11:23:22 · 318 阅读 · 0 评论 -
LeetCode-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原创 2014-08-18 11:41:31 · 349 阅读 · 0 评论 -
LeetCode-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.Input:Digit st原创 2014-08-18 12:01:34 · 523 阅读 · 0 评论 -
LeetCode-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:Elements in a triplet (a,b,c原创 2014-08-18 14:19:40 · 412 阅读 · 0 评论 -
LeetCode-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). Fin原创 2014-08-18 14:53:53 · 382 阅读 · 0 评论 -
LeetCode-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 ca原创 2014-08-18 21:31:39 · 325 阅读 · 0 评论 -
LeetCode-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:Element原创 2014-08-18 13:45:03 · 318 阅读 · 0 评论 -
LeetCode-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 exact原创 2014-08-18 14:02:30 · 322 阅读 · 0 评论 -
LeetCode-Longest Common Prefix
Write a function to find the longest common prefix string amongst an array of strings.Solution:Code:原创 2014-08-18 14:31:23 · 441 阅读 · 0 评论 -
LeetCode-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 st原创 2014-08-18 19:55:07 · 720 阅读 · 0 评论 -
LeetCode-Palindrome Number
Determine whether an integer is a palindrome. Do this without extra space.click to show spoilers.Some hints:Could negative integers be palindromes? (ie, -1)If you are thinking of convertin原创 2014-08-18 21:18:37 · 379 阅读 · 0 评论 -
LeetCode-Reverse Integer
Reverse digits of an integer.Example1: x = 123, return 321Example2: x = -123, return -321click to show spoilers.Have you thought about this?Here are some good questions to ask before c原创 2014-08-18 21:44:03 · 334 阅读 · 0 评论 -
LeetCode-ZigZag Conversion
The string "PAYPALISHIRING" is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility)P A H NA P L S I原创 2014-08-19 13:25:07 · 297 阅读 · 0 评论