- 博客(50)
- 收藏
- 关注
原创 560. Subarray Sum Equals K 题解
560. Subarray Sum Equals K 题解题目描述:Given an array of integers and an integer k, you need to find the total number of continuous subarrays whose sum equals to k.Example 1:Input
2017-06-30 16:21:56 294
原创 522. Longest Uncommon Subsequence II 题解
522. Longest Uncommon Subsequence II 题解题目描述:Given a list of strings, you need to find the longest uncommon subsequence among them. The longest uncommon subsequence is defined as the lon
2017-06-27 17:31:21 373
原创 525. Contiguous Array 题解
525. Contiguous Array 题解题目描述:Given a binary array, find the maximum length of a contiguous subarray with equal number of 0 and 1.Example 1:Input: [0,1]Output: 2Explanation: [0,
2017-06-27 15:41:58 305
原创 算法概论 8.3习题证明
算法概论 习题 8.3题目描述:吝啬SAT问题是这样的:给定一组子句(每个子句都是其中文字的析取)和整数k,求一个最多有k个变量为true的满足赋值——如果该赋值存在。证明吝啬SAT是NP-完全问题。什么是SAT问题?SAT问题也称为合取范式的可满足问题,一个合取范式形如:A1∧A2∧…∧An,子句Ai(1≤i≤n)形如:a1∨a2∨…∨ak,其
2017-06-23 16:45:16 440
原创 423. Reconstruct Original Digits from English 题解
423. Reconstruct Original Digits from English 题解题目描述:Given a non-empty string containing an out-of-order English representation of digits 0-9, output the digits in ascending order.
2017-06-22 21:07:14 254
原创 343. Integer Break 题解
343. Integer Break 题解题目描述:Given a positive integer n, break it into the sum of at least two positive integers and maximize the product of those integers. Return the maximum product y
2017-06-22 21:03:41 184
原创 416. Partition Equal Subset Sum 题解
416. Partition Equal Subset Sum 题解题目描述:Given a non-empty array containing only positive integers, find if the array can be partitioned into two subsets such that the sum of eleme
2017-06-19 17:01:13 251
原创 328. Odd Even Linked List 题解
328. Odd Even Linked List 题解题目描述: Given a singly linked list, group all odd nodes together followed by the even nodes. Please note here we are talking about the node numbe
2017-06-14 14:39:34 242
原创 228. Summary Ranges 题解
228. Summary Ranges 题解题目描述:Given a sorted integer array without duplicates, return the summary of its ranges.For example, given [0,1,2,4,5,7], return ["0->2","4->5","7"].
2017-06-08 12:54:45 262
原创 240. Search a 2D Matrix II 题解
240. Search a 2D Matrix II 题解题目描述:Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the following properties:Integers in each ro
2017-06-06 11:18:40 268
原创 24. Swap Nodes in Pairs 题解
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.
2017-06-01 13:13:37 258
原创 2. Add Two Numbers 题解
2. Add Two Numbers 题解题目描述:You are given two non-empty linked lists representing two non-negative integers. The digits are stored in reverse order and each of their nodes contain
2017-05-31 20:29:42 252
原创 357. Count Numbers with Unique Digits 题解
357. Count Numbers with Unique Digits 题解题目描述:Given a non-negative integer n, count all numbers with unique digits, x, where 0 ≤ x n.Example:Given n = 2, return 91. (The answer
2017-05-25 17:47:35 316
原创 6. ZigZag Conversion 题解
6. 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 f
2017-05-24 21:34:45 217
原创 54. Spiral Matrix 题解
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:[
2017-05-19 18:53:44 349
原创 18. 4Sum 题解
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 t
2017-05-17 14:44:09 214
原创 144. Binary Tree Preorder Traversal 题解
144. Binary Tree Preorder Traversal题解题目描述:Given a binary tree, return the preorder traversal of its nodes' values.For example:Given binary tree {1,#,2,3}, 1 \
2017-05-12 22:39:20 212
原创 15. 3Sum 题解
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
2017-05-09 19:56:07 212
原创 542. 01 Matrix 题解
542. 01 Matrix题目描述:Given a matrix consists of 0 and 1, find the distance of the nearest 0 for each cell.The distance between two adjacent cells is 1.Example 1: Input:0 0 0
2017-05-06 14:25:17 412
原创 147. Insertion Sort List 题解
147. Insertion Sort List题解题目描述:Sort a linked list using insertion sort.题目链接:147. Insertion Sort List算法描述: 题目很简单,一句话,对一个链表进行排序(默认为从小到大),返回排序好的链表。
2017-05-04 12:10:09 224
原创 334. Increasing Triplet Subsequence 题解
334. Increasing Triplet Subsequence 题解题目描述:Given an unsorted array return whether an increasing subsequence of length 3 exists or not in the array.Formally the function should:
2017-04-26 22:39:26 285
原创 49. Group Anagrams 题解
49. Group Anagrams 题解题目描述:Given an array of strings, group anagrams together.For example, given: ["eat", "tea", "tan", "ate", "nat", "bat"], Return:[ ["ate", "eat","tea
2017-04-23 23:15:08 282
原创 341. Flatten Nested List Iterator 题解
341. Flatten Nested List Iterator 题解题目描述:Given a nested list of integers, implement an iterator to flatten it.Each element is either an integer, or a list -- whose elements may a
2017-04-20 11:54:36 303
原创 134. Gas Station 题解
134. Gas Station 题解题目描述:There are N gas stations along a circular route, where the amount of gas at station i is gas[i].You have a car with an unlimited gas tank and it costs cos
2017-04-18 23:18:11 231
原创 222. Count Complete Tree Nodes 题解
222. Count Complete Tree Nodes题解题目描述:Given a complete binary tree, count the number of nodes.Definition of a complete binary tree from Wikipedia:In a complete binary tree eve
2017-04-15 13:45:38 242
原创 56. Merge Intervals 题解
56. Merge Intervals题解题目描述:Given a collection of intervals, merge all overlapping intervals.For example,Given [1,3],[2,6],[8,10],[15,18],return [1,6],[8,10],[15,18].题目
2017-04-13 23:52:59 263
原创 397. Integer Replacement 题解
397. Integer Replacement 题解题目描述:Given a positive integer n and you can do operations as follow:If n is even, replace n with n/2.If n is odd, you can replace n with either n + 1
2017-04-10 15:44:05 207
原创 60. Permutation Sequence 题解
60. Permutation Sequence题解题目描述:The set [1,2,3,…,n] contains a total of n! unique permutations.By listing and labeling all of the permutations in order,We get the following
2017-04-06 20:42:33 258
原创 398. Random Pick Index 题解
398. Random Pick Index 题解题目描述:Given an array of integers with possible duplicates, randomly output the index of a given target number. You can assume that the given target number mu
2017-04-03 20:43:22 287
原创 162. Find Peak Element 题解
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 in
2017-03-30 20:26:42 424
原创 152. Maximum Product Subarray 题解
152. Maximum Product Subarray 题解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
2017-03-29 21:38:54 288
原创 153. Find Minimum in Rotated Sorted Array 题解
153. Find Minimum in Rotated Sorted Array 题目描述:Suppose an array sorted in ascending order is rotated at some pivot unknown to you beforehand.(i.e., 0 1 2 4 5 6 7 might become 4 5 6
2017-03-27 11:45:27 532
原创 89. Gray Code 题解
89. Gray Code题目描述:The gray code is a binary numeral system where two successive values differ in only one bit.Given a non-negative integer n representing the total number of bits in
2017-03-21 20:53:25 427
原创 200. Number of Islands 题解
200. Number of Islands 题解题目描述:Given a 2d grid map of '1's (land) and '0's (water), count the number of islands. An island is surrounded by water and is formed by connecting adjacent la
2017-03-19 17:43:47 306
原创 22. Generate Parentheses 题解
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:
2017-03-14 21:41:32 186
原创 112. Path Sum 题解
112. Path Sum题目描述:Given a binary tree and a sum, determine if the tree has a root-to-leaf path such that adding up all the values along the path equals the given sum.For example:Given
2017-03-13 16:53:30 181
原创 394. Decode String 题解
394. Decode String题解题目描述:Given an encoded string, return it's decoded string.The encoding rule is: k[encoded_string], where the encoded_string inside the square brackets is being
2017-03-13 15:42:59 232
原创 Bulb Switcher 题解
319. Bulb Switcher题目描述:There are n bulbs that are initially off. You first turn on all the bulbs. Then, you turn off every second bulb. On the third round, you toggle every third bul
2017-03-09 13:24:42 213
原创 Combination Sum 题解
39. 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
2017-03-08 16:26:10 258
原创 Product of Array Except Self 题解
238. Product of Array Except Self题目描述:Given an array of n integers where n > 1, nums, return an array output such that output[i] is equal to the product of all the elements of nums exc
2017-03-07 10:54:19 217
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人