摘要: Given a binary tree, find the lowest common ancestor (LCA) of two given nodes in the tree. According to the definition of LCA on Wikipedia: “The lowes 阅读全文
posted @ 2016-01-29 14:38 fenshen371 阅读(127) 评论(0) 推荐(0) 编辑
摘要: Given a binary search tree (BST), find the lowest common ancestor (LCA) of two given nodes in the BST. According to the definition of LCA on Wikipedia 阅读全文
posted @ 2016-01-29 14:13 fenshen371 阅读(138) 评论(0) 推荐(0) 编辑
摘要: The gray code is a binary numeral system where two successive values differ in only one bit. Given a non-negative integer n representing the total num 阅读全文
posted @ 2016-01-29 10:32 fenshen371 阅读(158) 评论(0) 推荐(0) 编辑
摘要: Preorder 1 class Solution { 2 public: 3 vector<int> preorderTraversal(TreeNode* root) { 4 vector<int> res; 5 if (!root) return res; 6 stack<TreeNode * 阅读全文
posted @ 2016-01-29 09:52 fenshen371 阅读(144) 评论(0) 推荐(0) 编辑
摘要: Given a binary tree, return the preorder traversal of its nodes' values. For example:Given binary tree {1,#,2,3}, 1 \ 2 / 3 return [1,2,3]. 思路:递归和迭代。 阅读全文
posted @ 2016-01-29 08:00 fenshen371 阅读(108) 评论(0) 推荐(0) 编辑
摘要: Given a binary tree, return the zigzag level order traversal of its nodes' values. (ie, from left to right, then right to left for the next level and 阅读全文
posted @ 2016-01-29 06:51 fenshen371 阅读(149) 评论(0) 推荐(0) 编辑
摘要: Given a binary tree, determine if it is height-balanced. For this problem, a height-balanced binary tree is defined as a binary tree in which the dept 阅读全文
posted @ 2016-01-29 04:45 fenshen371 阅读(124) 评论(0) 推荐(0) 编辑
摘要: Given an array of strings, group anagrams together. For example, given: ["eat", "tea", "tan", "ate", "nat", "bat"], Return: [ ["ate", "eat","tea"], [" 阅读全文
posted @ 2016-01-29 03:35 fenshen371 阅读(171) 评论(0) 推荐(0) 编辑