摘要: 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 阅读(147) 评论(0) 推荐(0) 编辑
摘要: 解决方法:以管理员权限打开/usr/bin/dia ,做如下修改#dia-gnome --integrated "$@"dia-gnome "$@" 阅读全文
posted @ 2014-03-28 21:12 Eason Liu 阅读(308) 评论(0) 推荐(0) 编辑
摘要: 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 阅读(169) 评论(0) 推荐(0) 编辑
摘要: 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 阅读(804) 评论(1) 推荐(0) 编辑
摘要: 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 阅读(231) 评论(0) 推荐(0) 编辑
摘要: 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 阅读(197) 评论(0) 推荐(0) 编辑
摘要: 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 阅读(182) 评论(0) 推荐(0) 编辑
摘要: 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 阅读(374) 评论(0) 推荐(0) 编辑
摘要: 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 阅读(137) 评论(0) 推荐(0) 编辑
摘要: 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 阅读(162) 评论(0) 推荐(0) 编辑
摘要: 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 阅读(529) 评论(0) 推荐(0) 编辑
摘要: break: 跳出循环,执行for循环下面的语句。continue: 跳出本次循环,执行下次循环。 阅读全文
posted @ 2014-03-28 14:14 Eason Liu 阅读(648) 评论(0) 推荐(0) 编辑