摘要: Depth-first traversalpreorder(node) if node == null then return visit(node) preorder(node.left) preorder(node.right) iterativePreorder(node) parentStack = empty stack while not parentStack.isEmpty() or node != null if node != null then parentStack.push(node) visit(node) ... 阅读全文
posted @ 2013-01-09 13:54 西施豆腐渣 阅读(186) 评论(0) 推荐(0) 编辑
摘要: Given a binary tree, find its maximum depth.The maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node.1. recursive way./** * Definition for binary tree * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * ... 阅读全文
posted @ 2013-01-09 12:48 西施豆腐渣 阅读(136) 评论(0) 推荐(0) 编辑
摘要: Given a string, find the length of the longest substring without repeating characters. For example, the longest substring without repeating letters for "abcabcbb" is "abc", which the length is 3. For "bbbbb" the longest substring is "b", with the length of 1.m 阅读全文
posted @ 2013-01-09 07:14 西施豆腐渣 阅读(155) 评论(0) 推荐(0) 编辑
摘要: Write a function to find the longest common prefix string amongst an array of strings.reminders: 1. class Solution { public: string longestCommonPrefix(vector<string> &strs) { // Start typing your C/C++ solution below // DO NOT write int main() function // in this questio... 阅读全文
posted @ 2013-01-09 06:29 西施豆腐渣 阅读(160) 评论(0) 推荐(0) 编辑
摘要: Given a stringsconsists of upper/lower-case alphabets and empty space characters' ', return the length of last word in the string.If the last word does not exist, return 0.Note:A word is defined as a character sequence consists of non-space characters only.For example,Givens="Hello Worl 阅读全文
posted @ 2013-01-09 06:04 西施豆腐渣 阅读(146) 评论(0) 推荐(0) 编辑
摘要: Given an integer, convert it to a roman numeral.Input is guaranteed to be within the range from 1 to 3999.my reminders: string is different vector, which can use position instead of iterator to assign a element. because string's element is char but vector is templete. also string can insert or o 阅读全文
posted @ 2013-01-09 05:37 西施豆腐渣 阅读(161) 评论(0) 推荐(0) 编辑