摘要: Given a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST.1. 将LinkedList的值保存到一个数组中,转化成Convert Sorte... 阅读全文
posted @ 2014-05-10 22:18 一弦一仙 阅读(152) 评论(0) 推荐(0) 编辑
摘要: Given a binary tree, determine if it is a valid binary search tree (BST).Assume a BST is defined as follows:The left subtree of a node contains only n... 阅读全文
posted @ 2014-05-10 20:35 一弦一仙 阅读(134) 评论(0) 推荐(0) 编辑
摘要: 原文链接http://oj.leetcode.com/problems/search-in-rotated-sorted-array-ii/http://blog.csdn.net/linhuanmars/article/details/20588511这道题是二分查找Search Insert P... 阅读全文
posted @ 2014-05-10 19:53 一弦一仙 阅读(148) 评论(0) 推荐(0) 编辑
摘要: Suppose a sorted array is rotated at some pivot unknown to you beforehand.(i.e.,0 1 2 4 5 6 7might become4 5 6 7 0 1 2).You are given a target value t... 阅读全文
posted @ 2014-05-10 19:13 一弦一仙 阅读(181) 评论(0) 推荐(0) 编辑
摘要: Given amxnmatrix, if an element is 0, set its entire row and column to 0. Do it in place.click to show follow up.Follow up:Did you use extra space?A s... 阅读全文
posted @ 2014-05-10 18:49 一弦一仙 阅读(203) 评论(0) 推荐(0) 编辑
摘要: Implementint sqrt(int x).Compute and return the square root ofx.原文地址:http://kb.cnblogs.com/page/189867/好吧,我承认我标题党了,不过既然你来了,就认真看下去吧,保证你有收获。 我们平时经常会有一些... 阅读全文
posted @ 2014-05-10 16:10 一弦一仙 阅读(206) 评论(0) 推荐(0) 编辑
摘要: Given an integer, convert it to a roman numeral.Input is guaranteed to be within the range from 1 to 3999.public class Solution { public String int... 阅读全文
posted @ 2014-05-10 15:51 一弦一仙 阅读(168) 评论(0) 推荐(0) 编辑
摘要: 贪心算法1.性质贪心算法通过一系列的选择来得到问题的解。它所做的每一个选择都是当前状态下局部的最好选择,即贪心选择。贪心选择的一般特征:贪心选择性质和最优子结构性质。在动态规划算法中,每步所作的选择往往依赖于相关子问题的解。因而只有在解出相关子问题后,才能作出选择。而在贪心算法中,仅在当前状态下作出... 阅读全文
posted @ 2014-05-10 15:15 一弦一仙 阅读(482) 评论(0) 推荐(0) 编辑
摘要: 转载:http://blog.csdn.net/fightforyourdream/article/details/14503469题目:最佳时间买入卖出股票:你有一个数组保存了股票在第i天的价钱,现在你最多进行两次买卖,但同一时间你手上只能保持一个股票,如何赚的最多思路:知道要用DP做,但是一开始... 阅读全文
posted @ 2014-05-09 15:23 一弦一仙 阅读(184) 评论(0) 推荐(0) 编辑
摘要: Say you have an array for which theithelement is the price of a given stock on dayi.Design an algorithm to find the maximum profit. You may complete a... 阅读全文
posted @ 2014-05-09 11:14 一弦一仙 阅读(143) 评论(0) 推荐(0) 编辑