摘要: 96. Unique Binary Search Trees Given n, how many structurally unique BST's (binary search trees) that store values 1...n? For example, Given n = 3, th 阅读全文
posted @ 2017-04-09 22:04 蓦然闻声 阅读(155) 评论(0) 推荐(0) 编辑
摘要: 530. Minimum Absolute Difference in BST Given a binary search tree with non-negative values, find the minimum absolute difference between values of an 阅读全文
posted @ 2017-04-09 22:03 蓦然闻声 阅读(228) 评论(0) 推荐(0) 编辑
摘要: 520. Detect Capital Given a word, you need to judge whether the usage of capitals in it is right or not. We define the usage of capitals in a word to 阅读全文
posted @ 2017-04-09 22:02 蓦然闻声 阅读(91) 评论(0) 推荐(0) 编辑
摘要: 递归方法: 非递归:要借助栈,可以利用C++ STL中的stack。首先将根节点压栈,然后压入栈顶元素的左节点直到叶子节点,然后访问叶子节点后压入该节点的右子节点。 阅读全文
posted @ 2017-04-09 22:01 蓦然闻声 阅读(133) 评论(0) 推荐(0) 编辑
摘要: leetcode 105题,由树的前序序列和中序序列构建树结构。详细解答参考《剑指offer》page56. 先序遍历结果的第一个节点为根节点,在中序遍历结果中找到根节点的位置。然后就可以将问题拆分,递归求解。 阅读全文
posted @ 2017-04-09 22:01 蓦然闻声 阅读(195) 评论(0) 推荐(0) 编辑
摘要: 437. Path Sum III You are given a binary tree in which each node contains an integer value. Find the number of paths that sum to a given value. The pa 阅读全文
posted @ 2017-04-09 22:00 蓦然闻声 阅读(142) 评论(0) 推荐(0) 编辑
摘要: 500. Keyboard Row Given a List of words, return the words that can be typed using letters of alphabet on only one row's of American keyboard like the 阅读全文
posted @ 2017-04-09 21:59 蓦然闻声 阅读(357) 评论(0) 推荐(0) 编辑
摘要: 504. Base 7 Given an integer, return its base 7 string representation. Example 1: Input: 100 Output: "202" Example 2: Input: -7 Output: "-10" Note: Th 阅读全文
posted @ 2017-04-09 21:58 蓦然闻声 阅读(139) 评论(0) 推荐(0) 编辑
摘要: 28. Implement strStr() Implement strStr(). Returns the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack. 思 阅读全文
posted @ 2017-04-09 21:56 蓦然闻声 阅读(119) 评论(0) 推荐(0) 编辑
摘要: 459. Repeated Substring Pattern Given a non-empty string check if it can be constructed by taking a substring of it and appending multiple copies of t 阅读全文
posted @ 2017-04-09 21:55 蓦然闻声 阅读(92) 评论(0) 推荐(0) 编辑
摘要: 70. Climbing Stairs You are climbing a stair case. It takes n steps to reach to the top. Each time you can either climb 1 or 2 steps. In how many dist 阅读全文
posted @ 2017-04-09 21:55 蓦然闻声 阅读(129) 评论(0) 推荐(0) 编辑
摘要: 53. Maximum Subarray Find the contiguous subarray within an array (containing at least one number) which has the largest sum. For example, given the a 阅读全文
posted @ 2017-04-09 21:54 蓦然闻声 阅读(138) 评论(0) 推荐(0) 编辑
摘要: 326. Power of Three Given an integer, write a function to determine if it is a power of three. Follow up: Could you do it without using any loop / rec 阅读全文
posted @ 2017-04-09 21:53 蓦然闻声 阅读(142) 评论(0) 推荐(0) 编辑
摘要: Write an algorithm to determine if a number is "happy". A happy number is a number defined by the following process: Starting with any positive intege 阅读全文
posted @ 2017-04-09 21:53 蓦然闻声 阅读(92) 评论(0) 推荐(0) 编辑
摘要: 405. Convert a Number to Hexadecimal Given an integer, write an algorithm to convert it to hexadecimal. For negative integer, two’s complement method 阅读全文
posted @ 2017-04-09 21:52 蓦然闻声 阅读(186) 评论(0) 推荐(0) 编辑
摘要: 415. Add Strings Given two non-negative integers num1 and num2 represented as string, return the sum of num1 and num2. Note: 思路:控制num1的长度不小于num2的长度,在n 阅读全文
posted @ 2017-04-09 21:51 蓦然闻声 阅读(109) 评论(0) 推荐(0) 编辑
摘要: 108. Convert Sorted Array to Binary Search Tree 思路:利用一个有序数组构建一个平衡二叉排序树。直接递归构建,取中间的元素为根节点,然后分别构建左子树和右子树。 阅读全文
posted @ 2017-04-09 21:51 蓦然闻声 阅读(89) 评论(0) 推荐(0) 编辑
摘要: 501. Find Mode in Binary Search Tree Given a binary search tree (BST) with duplicates, find all the mode(s) (the most frequently occurred element) in 阅读全文
posted @ 2017-04-09 21:50 蓦然闻声 阅读(231) 评论(0) 推荐(0) 编辑
摘要: Given an array containing n distinct numbers taken from 0, 1, 2, ..., n, find the one that is missing from the array. For example, Given nums = [0, 1, 阅读全文
posted @ 2017-04-09 21:49 蓦然闻声 阅读(110) 评论(0) 推荐(0) 编辑
摘要: Given n points in the plane that are all pairwise distinct, a "boomerang" is a tuple of points (i, j, k) such that the distance between iand j equals 阅读全文
posted @ 2017-04-09 21:49 蓦然闻声 阅读(96) 评论(0) 推荐(0) 编辑