
Leetcode
秤和砣
这个作者很懒,什么都没留下…
展开
-
Best Time to Buy and Sell Stock
class Solution {public: int maxProfit(vector &prices) { // Note: The Solution object is instantiated only once and is reused by each test case. int solution = 0;转载 2014-04-28 15:10:46 · 403 阅读 · 0 评论 -
Plus One
Given a non-negative number represented as an array of digits, plus one to the number.The digits are stored such that the most significant digit is at the head of the list.class Solution {publ转载 2014-04-28 15:02:05 · 327 阅读 · 0 评论 -
Minimum Path Sum
Given a m x n grid filled with non-negative numbers, find a path from top left to bottom right which minimizes the sum of all numbers along its path.Note: You can only move either down or right at转载 2014-04-29 15:14:01 · 282 阅读 · 0 评论 -
Binary Tree Postorder Traversal
Given a binary tree, return the postorder traversal of its nodes' values.For example:Given binary tree {1,#,2,3}, 1 \ 2 / 3return [3,2,1].// RECURSIVE VERSION:转载 2014-04-28 15:47:39 · 330 阅读 · 0 评论 -
Permutations
// NON-SWAP VERSION:class Solution {public: vector > solution; vector singleSolution; void helper(vector & num, vector & visited){ if (singleSolution.size()==num.size转载 2014-04-28 13:54:18 · 318 阅读 · 0 评论 -
Generate Parentheses
void helper(vector & solution, string & singleSolution, int numofleft, int numofright, int n){ if (singleSolution.size()==(2*n)) solution.push_back(singleSolutio转载 2014-04-28 14:43:52 · 299 阅读 · 0 评论 -
Binary Tree Level Order Traversal II
Given a binary tree, return the bottom-up level order traversal of its nodes' values. (ie, from left to right, level by level from leaf to root).For example:Given binary tree {3,9,20,#,#,15,7},转载 2014-04-28 14:19:42 · 186 阅读 · 0 评论 -
Gray Code
class Solution {public: vector grayCode(int n) { // Start typing your C/C++ solution below // DO NOT write int main() function vector result; result.pu转载 2014-04-28 13:10:12 · 281 阅读 · 0 评论