随笔分类 -  leetcode

摘要:Reverse a linked list from positionmton. Do it in-place and in one-pass.For example:Given1->2->3->4->5->NULL,m= 2 andn= 4,return1->4->3->2->5->NULL.No... 阅读全文
posted @ 2014-05-11 15:05 一弦一仙 阅读(112) 评论(0) 推荐(0)
摘要:Given a set ofnon-overlappingintervals, insert a new interval into the intervals (merge if necessary).You may assume that the intervals were initially... 阅读全文
posted @ 2014-05-11 14:41 一弦一仙 阅读(145) 评论(0) 推荐(0)
摘要:Sort a linked list using insertion sort.//用到O(N)的额外空间public class Solution { public ListNode insertionSortList(ListNode head) { if(head==nul... 阅读全文
posted @ 2014-05-11 12:58 一弦一仙 阅读(154) 评论(0) 推荐(0)
摘要: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 一弦一仙 阅读(162) 评论(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 一弦一仙 阅读(141) 评论(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 一弦一仙 阅读(157) 评论(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 一弦一仙 阅读(187) 评论(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 一弦一仙 阅读(208) 评论(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 一弦一仙 阅读(222) 评论(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 一弦一仙 阅读(175) 评论(0) 推荐(0)
摘要:转载:http://blog.csdn.net/fightforyourdream/article/details/14503469题目:最佳时间买入卖出股票:你有一个数组保存了股票在第i天的价钱,现在你最多进行两次买卖,但同一时间你手上只能保持一个股票,如何赚的最多思路:知道要用DP做,但是一开始... 阅读全文
posted @ 2014-05-09 15:23 一弦一仙 阅读(189) 评论(0) 推荐(0)
摘要:http://blog.unieagle.net/category/develop/%E7%AE%97%E6%B3%95/ 阅读全文
posted @ 2014-05-09 11:17 一弦一仙 阅读(142) 评论(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 一弦一仙 阅读(147) 评论(0) 推荐(0)
摘要:Say you have an array for which theithelement is the price of a given stock on dayi.If you were only permitted to complete at most one transaction (ie... 阅读全文
posted @ 2014-05-09 10:22 一弦一仙 阅读(147) 评论(0) 推荐(0)
摘要:Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center).For example, this binary tree is symmetric: 1 / \ ... 阅读全文
posted @ 2014-05-08 20:34 一弦一仙 阅读(160) 评论(0) 推荐(0)
摘要:http://oj.leetcode.com/problems/swap-nodes-in-pairs/Given a linked list, swap every two adjacent nodes and return its head.For example,Given1->2->3->4... 阅读全文
posted @ 2014-05-08 20:14 一弦一仙 阅读(149) 评论(0) 推荐(0)
摘要:http://oj.leetcode.com/problems/climbing-stairs/You are climbing a stair case. It takesnsteps to reach to the top.Each time you can either climb 1 or ... 阅读全文
posted @ 2014-05-08 20:08 一弦一仙 阅读(188) 评论(0) 推荐(0)
摘要:http://oj.leetcode.com/problems/maximum-subarray/Find the contiguous subarray within an array (containing at least one number) which has the largest s... 阅读全文
posted @ 2014-05-08 19:26 一弦一仙 阅读(193) 评论(0) 推荐(0)
摘要:Given a sorted array and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in or... 阅读全文
posted @ 2014-05-07 23:15 一弦一仙 阅读(124) 评论(0) 推荐(0)
摘要:http://oj.leetcode.com/problems/balanced-binary-tree/http://blog.csdn.net/fightforyourdream/article/details/18693131Given a binary tree, determine if ... 阅读全文
posted @ 2014-05-07 22:55 一弦一仙 阅读(132) 评论(0) 推荐(0)