算法
shawnNg
没有我开不了的机!
展开
-
(LeetCode) 279. Perfect Squares
279. Perfect Squares原创 2017-03-05 14:30:53 · 160 阅读 · 0 评论 -
(LeetCode) 494. Target Sum
494. Target SumYou are given a list of non-negative integers, a1, a2, …, an, and a target, S. Now you have 2 symbols + and -. For each integer, you should choose one from + and - as its new symbol.Find原创 2017-05-30 21:21:29 · 213 阅读 · 0 评论 -
(LeetCode) 62. Unique Paths
62. Unique PathsA 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 trying to原创 2017-05-30 21:24:29 · 133 阅读 · 0 评论 -
(LeetCode) 338. Counting Bits
338. Counting BitsGiven 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:原创 2017-05-30 21:26:55 · 154 阅读 · 0 评论 -
(LeetCode) 343. Integer Break
343. Integer BreakGiven 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 you can get.For example, giv原创 2017-05-30 21:34:04 · 161 阅读 · 0 评论 -
(LeetCode) 421. Maximum XOR of Two Numbers in an Array
421. Maximum XOR of Two Numbers in an ArrayGiven a non-empty array of numbers, a0, a1, a2, … , an-1, where 0 ≤ ai < 231.Find the maximum result of ai XOR aj, where 0 ≤ i, j < n.Could you do this in O(n原创 2017-05-30 21:46:53 · 174 阅读 · 0 评论 -
(LeetCode) 215. Kth Largest Element in an Array
215. Kth Largest Element in an ArrayFind the kth largest element in an unsorted array. Note that it is the kth largest element in the sorted order, not the kth distinct element.For example, Given [3,2原创 2017-05-30 21:51:50 · 152 阅读 · 0 评论 -
(LeetCode) 491. Increasing Subsequences
491. Increasing SubsequencesGiven an integer array, your task is to find all the different possible increasing subsequences of the given array, and the length of an increasing subsequence should be at原创 2017-05-30 21:54:31 · 207 阅读 · 0 评论 -
(LeetCode) 204. Count Primes
204. Count PrimesDescription:Count the number of prime numbers less than a non-negative number, n.代码int countPrimes(int n) { if (n<=2) return 0; vector<bool> passed(n, false); int sum = 1;原创 2017-05-30 22:01:13 · 144 阅读 · 0 评论 -
(LeetCode) 328. Odd Even Linked List
328. Odd Even Linked ListGiven a singly linked list, group all odd nodes together followed by the even nodes. Please note here we are talking about the node number and not the value in the nodes.You sh原创 2017-05-30 21:16:56 · 130 阅读 · 0 评论 -
(LeetCode) 46. Permutations
46. PermutationsGiven 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原创 2017-05-30 21:11:25 · 149 阅读 · 0 评论 -
(LeetCode) 199. Binary Tree Right Side View
199. Binary Tree Right Side ViewGiven a binary tree, imagine yourself standing on the right side of it, return the values of the nodes you can see ordered from top to bottom.For example: Given the fol原创 2017-05-30 21:06:09 · 166 阅读 · 0 评论 -
(LeetCode) 344. Reverse String
344. Reverse String原创 2017-03-21 00:17:06 · 151 阅读 · 0 评论 -
(LeetCode) 268. Missing Number
268. Missing Number原创 2017-03-21 00:42:06 · 143 阅读 · 0 评论 -
(LeetCode) 191. Number of 1 Bits
191. Number of 1 Bits原创 2017-03-21 00:42:43 · 140 阅读 · 0 评论 -
(LeetCode) 129. Sum Root to Leaf Numbers
129. Sum Root to Leaf NumbersGiven a binary tree containing digits from 0-9 only, each root-to-leaf path could represent a number.An example is the root-to-leaf path 1->2->3 which represents the number原创 2017-04-11 18:03:23 · 169 阅读 · 0 评论 -
(LeetCode) 114. Flatten Binary Tree to Linked List
114. Flatten Binary Tree to Linked ListGiven a binary tree, flatten it to a linked list in-place.For example, Given 1 / \ 2 5 / \ \ 3 4 6The flattened tree should look like:原创 2017-04-11 18:36:43 · 140 阅读 · 0 评论 -
(LeetCode) 108. Convert Sorted Array to Binary Search Tree
108. Convert Sorted Array to Binary Search TreeGiven an array where elements are sorted in ascending order, convert it to a height balanced BST.思路将升序排序的数组变成一个平衡二叉搜索树,只需要在中间切断,将数组分为左右子树,继续递归下去。代码class S原创 2017-04-12 12:24:46 · 202 阅读 · 0 评论 -
(LeetCode) 543. Diameter of Binary Tree
543. Diameter of Binary TreeGiven a binary tree, you need to compute the length of the diameter of the tree. The diameter of a binary tree is the length of the longest path between any two nodes in a t原创 2017-04-12 12:27:45 · 234 阅读 · 0 评论 -
(LeetCode) 279. Perfect Squares
279. Perfect SquaresGiven a positive integer n, find the least number of perfect square numbers (for example, 1, 4, 9, 16, ...) which sum to n.For example, given n = 12, return 3 because 12 = 4 + 4 + 4原创 2017-05-30 20:57:44 · 116 阅读 · 0 评论 -
吝啬SAT是NP-完全问题
《算法概论》8.3吝啬SAT问题是这样的:给定一组子句 (每个子句都是其中文字的析取) 和整数 k,求一个最多有 k 个变量为 true 的满足赋值——如果该赋值存在。证明吝啬SAT是NP-完全问题。证明:已知SAT问题是NPC问题。要证明吝啬SAT问题是NPC问题,只须证明,一个SAT问题可以在多项式时间归约到吝啬SAT问题。假设SAT问题有n个变量,令吝啬SAT问题中的k为SAT问题中的n,即在原创 2017-07-14 13:12:50 · 436 阅读 · 0 评论