03 2014 档案

[Leetcode] Populating Next Right Pointers in Each Node
摘要:Given a binary tree struct TreeLinkNode { TreeLinkNode *left; TreeLinkNode *right; TreeLinkNode *next; }Populate each next pointer to point to its next right node. If there is no next right node, the next pointer should be set toNULL.Initially, all next pointers are set toNULL.N... 阅读全文

posted @ 2014-03-31 22:32 Eason Liu 阅读(149) 评论(0) 推荐(0)

[Leetcode] Minimum Path Sum
摘要:Given amxngrid filled with non-negative numbers, find a path from top left to bottom right whichminimizesthe sum of all numbers along its path.Note:You can only move either down or right at any point in time.水 1 class Solution { 2 public: 3 int minPathSum(vector > &grid) { 4 int m = grid... 阅读全文

posted @ 2014-03-31 21:53 Eason Liu 阅读(154) 评论(0) 推荐(0)

[Leetcode] Unique Paths
摘要:A robot is located at the top-left corner of amxngrid (marked 'Start' in the diagram below).The robot can only move either down or right at any point ... 阅读全文

posted @ 2014-03-31 19:18 Eason Liu 阅读(154) 评论(0) 推荐(0)

[Leetcode] Unique Paths II
摘要:Follow up for "Unique Paths":Now consider if some obstacles are added to the grids. How many unique paths would there be?An obstacle and empty space is marked as1and0respectively in the grid.For example,There is one obstacle in the middle of a 3x3 grid as illustrated below.[ [0,0,0], [0,1, 阅读全文

posted @ 2014-03-31 19:16 Eason Liu 阅读(169) 评论(0) 推荐(0)

[Leetcode] Path Sum II
摘要:Given a binary tree and a sum, find all root-to-leaf paths where each path's sum equals the given sum.For example:Given the below binary tree andsum = 22, 5 / \ 4 8 / / \ 11 13 4 / \ / \ 7 2 5 1return[ [5,4,11,2]... 阅读全文

posted @ 2014-03-31 01:16 Eason Liu 阅读(150) 评论(0) 推荐(0)

[Leetcode] 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 the below binary tree andsum = 22, 5 / \ 4 8 / / \ 11 13 4 / \ ... 阅读全文

posted @ 2014-03-31 01:08 Eason Liu 阅读(165) 评论(0) 推荐(0)

[Leetcode] Multiply Strings
摘要:Given two numbers represented as strings, return multiplication of the numbers as a string.Note: The numbers can be arbitrarily large and are non-negative.大数乘法,注意前置0的处理。 1 class Solution { 2 public: 3 string multiply(string num1, string num2) { 4 string num3; 5 num3.resize(num1.s... 阅读全文

posted @ 2014-03-31 00:58 Eason Liu 阅读(224) 评论(0) 推荐(0)

[Leetcode] Longest Substring Without Repeating Characters
摘要:Given a string, find the length of the longest substring without repeating characters. For example, the longest substring without repeating letters fo... 阅读全文

posted @ 2014-03-30 23:55 Eason Liu 阅读(174) 评论(0) 推荐(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].注意不能用n!来判断了,可以先排一下序,当序列逆序时结束。 1 class Solution { 2 public: 3 bool nextPermutation(vector &num) { 4 if... 阅读全文

posted @ 2014-03-29 14:23 Eason Liu 阅读(237) 评论(0) 推荐(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].与Next Permutation一样,n个元素的排列共有n!个,所以只要执行n!次next_permutation就行。 1 class Solution { 2 public: 3 bool nextPermutation(vector &num) { 阅读全文

posted @ 2014-03-29 14:16 Eason Liu 阅读(557) 评论(0) 推荐(0)

[Leetcode] Next Permutation
摘要:Implement next permutation, which rearranges numbers into the lexicographically next greater permutation of numbers.If such arrangement is not possibl... 阅读全文

posted @ 2014-03-29 13:34 Eason Liu 阅读(3923) 评论(0) 推荐(3)

(转) 共享个很棒的vim配置
摘要:发现了一个很棒的vim配置方法,现在共享给大家。https://github.com/kepbod/ivimivim - The Vim Distribution of Xiao-Ou ZhangSee ivim's states on GitEgoInstallationManual InstallA Vim/MacVim/gVim with version higher than 7.3 has been installed on your computer, and back up your origin vim stuff;Install Vundle to install a 阅读全文

posted @ 2014-03-29 00:49 Eason Liu 阅读(651) 评论(0) 推荐(0)

[Leetcode] String to Integer (atoi)
摘要:Implementatoito 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 cases.Notes:It is intended for this problem to be specified vaguely (ie, no given input specs). You are respo 阅读全文

posted @ 2014-03-28 22:06 Eason Liu 阅读(162) 评论(0) 推荐(0)

dia无法输入中文?
摘要:解决方法:以管理员权限打开/usr/bin/dia ,做如下修改#dia-gnome --integrated "$@"dia-gnome "$@" 阅读全文

posted @ 2014-03-28 21:12 Eason Liu 阅读(323) 评论(0) 推荐(0)

[Leetcode] Sum Root to Leaf Numbers
摘要:Given a binary tree containing digits from0-9only, each root-to-leaf path could represent a number.An example is the root-to-leaf path1->2->3which represents the number123.Find the total sum of all root-to-leaf numbers.For example, 1 / \ 2 3The root-to-leaf path1->2represents the number12.T 阅读全文

posted @ 2014-03-28 19:22 Eason Liu 阅读(182) 评论(0) 推荐(0)

[Leetcode] Interleaving String
摘要:Givens1,s2,s3, find whethers3is formed by the interleaving ofs1ands2.For example,Given:s1="aabcc",s2="dbbca",Whens3="aadbbcbcac", return true.Whens3="aadbbbaccc", return false.动态规划,类似于求最长公共子序列。 1 class Solution { 2 public: 3 bool isInterleave(string s1, string 阅读全文

posted @ 2014-03-28 16:30 Eason Liu 阅读(815) 评论(1) 推荐(0)

[Leetcode] Construct Binary Tree from Preorder and Inorder Traversal
摘要:Given preorder and inorder traversal of a tree, construct the binary tree.Note:You may assume that duplicates do not exist in the tree.没什么好说的,了解原理即可,使用递归。 1 /** 2 * Definition for binary tree 3 * struct TreeNode { 4 * int val; 5 * TreeNode *left; 6 * TreeNode *right; 7 * TreeNo... 阅读全文

posted @ 2014-03-28 14:43 Eason Liu 阅读(238) 评论(0) 推荐(0)

[Leetcode] Two Sum
摘要:Given an array of integers, find two numbers such that they add up to a specific target number.The function twoSum should return indices of the two nu... 阅读全文

posted @ 2014-03-28 14:38 Eason Liu 阅读(208) 评论(0) 推荐(0)

[Leetcode] Climbing Stairs
摘要:You are climbing a stair case. It takesnsteps to reach to the top.Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb... 阅读全文

posted @ 2014-03-28 14:34 Eason Liu 阅读(195) 评论(0) 推荐(0)

[Leetcode] Reverse Words in a String
摘要:Given an input string, reverse the string word by word.For example,Given s = "the sky is blue",return "blue is sky the".click to show clarification.Clarification:What constitutes a word?A sequence of non-space characters constitutes a word.Could the input string contain leading o 阅读全文

posted @ 2014-03-28 14:31 Eason Liu 阅读(380) 评论(0) 推荐(0)

[Leetcode] Valid Palindrome
摘要:Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases.For example,"A man, a plan, a canal: Pana... 阅读全文

posted @ 2014-03-28 14:27 Eason Liu 阅读(145) 评论(0) 推荐(0)

[Leetcode] First Missing Positive
摘要:Given an unsorted integer array, find the first missing positive integer.For example,Given[1,2,0]return3,and[3,4,-1,1]return2.Your algorithm should run inO(n) time and uses constant space.方法比较巧,先把所有元素的值-1,重新组织元素使A[i] = i,这样只要找到第一个A[i] != i 的 i。注意要用while循环,for循环的continue是从下一次循环开始的。 1 class Solution { 阅读全文

posted @ 2014-03-28 14:23 Eason Liu 阅读(168) 评论(0) 推荐(0)

[Leetcode] Simplify Path
摘要:Given an absolute path for a file (Unix-style), simplify it.For example,path="/home/", =>"/home"path="/a/./b/../../c/", =>"/c"用栈实现即可,注意一些特殊情况的判断。 1 class Solution { 2 public: 3 string simplifyPath(string path) { 4 stack s; 5 string str; 6 int a, b; 7 boo 阅读全文

posted @ 2014-03-28 14:18 Eason Liu 阅读(539) 评论(0) 推荐(0)

for循环中的break与continue
摘要:break: 跳出循环,执行for循环下面的语句。continue: 跳出本次循环,执行下次循环。 阅读全文

posted @ 2014-03-28 14:14 Eason Liu 阅读(671) 评论(0) 推荐(0)