题目链接:https://leetcode.com/problems/maximum-product-subarray/较麻烦的解法:先判断数组中有没有0,有的话可以转换为求"0之前"和"0之后"两部分的较大值。遍历,记录数组中负数的个数:偶数:由于数组中都是整数,最大值即这些值的乘积。奇数:有以下...
分类:
其他好文 时间:
2015-04-05 23:22:57
阅读次数:
164
题目链接:https://leetcode.com/problems/n-queens-ii/N皇后问题的位运算实现。 1 class Solution 2 { 3 public: 4 int totalNQueens(int n) 5 { 6 upperLimit ...
分类:
其他好文 时间:
2015-04-05 23:21:00
阅读次数:
167
题目链接:https://leetcode.com/problems/linked-list-cycle/判断一个链表中是否有环,可以设置两个指针,第一个每次前进一格,第二个每次前进两格。对于前进两格的指针,需要先判断前进一格时是否为 NULL :如果不判断是不是 NULL ,取两次 next 可能...
分类:
其他好文 时间:
2015-04-05 23:19:42
阅读次数:
179
题目链接:https://leetcode.com/problems/binary-tree-maximum-path-sum/题中要求 maxPathSum(TreeNode *root)函数返回二叉树中最大的"Path Sum"。而这个最大的"Path Sum"可以被分解为三部分之和:"左子树的...
分类:
其他好文 时间:
2015-04-05 23:11:44
阅读次数:
158
https://leetcode.com/problems/longest-valid-parentheses/Given a string containing just the characters'('and')', find the length of the longest valid (...
分类:
其他好文 时间:
2015-04-05 21:38:33
阅读次数:
136
题意: https://leetcode.com/problems/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 a...
分类:
其他好文 时间:
2015-04-05 17:33:39
阅读次数:
105
一:Integer to Roman
题目:
Given an integer, convert it to a roman numeral.
Input is guaranteed to be within the range from 1 to 3999.
链接:https://leetcode.com/problems/integer-to-roman/
分析:此题...
分类:
其他好文 时间:
2015-04-05 16:02:09
阅读次数:
156
一:Reverse Integer
题目:
Reverse digits of an integer.
Example1: x = 123, return 321
Example2: x = -123, return -321
链接:https://leetcode.com/problems/reverse-integer/
分析:这题通过不断取余将余数存放在一个vecto...
分类:
其他好文 时间:
2015-04-05 14:40:31
阅读次数:
161
题目链接:https://leetcode.com/problems/best-time-to-buy-and-sell-stock-iv/当 k ≥ prices.size() / 2 时:题目等价于 k 无限大的情形。当 k < prices.size() / 2 时:用dp[m][n+1]表示...
分类:
其他好文 时间:
2015-04-04 18:12:39
阅读次数:
177
https://leetcode.com/problems/permutations-ii/Given a collection of numbers that might contain duplicates, return all possible unique permutations.For...
分类:
其他好文 时间:
2015-04-03 20:59:35
阅读次数:
124