摘要: Design a stack that supports push, pop, top, and retrieving the minimum element in constant time.push(x) -- Push element x onto stack.pop() -- Removes... 阅读全文
posted @ 2015-02-17 00:22 江南第一少 阅读(146) 评论(0) 推荐(0)
摘要: All DNA is composed of a series of nucleotides abbreviated as A, C, G, and T, for example: "ACGAATTCCG". When studying DNA, it is sometimes useful to ... 阅读全文
posted @ 2015-02-07 05:39 江南第一少 阅读(109) 评论(0) 推荐(0)
摘要: The demons had captured the princess (P) and imprisoned her in the bottom-right corner of a dungeon. The dungeon consists of M x N rooms laid out in a... 阅读全文
posted @ 2015-01-28 22:39 江南第一少 阅读(140) 评论(0) 推荐(0)
摘要: Implement an iterator over a binary search tree (BST). Your iterator will be initialized with the root node of a BST.Callingnext()will return the next... 阅读全文
posted @ 2015-01-25 10:27 江南第一少 阅读(138) 评论(0) 推荐(0)
摘要: Given a list of non negative integers, arrange them such that they form the largest number.For example, given[3, 30, 34, 5, 9], the largest formed num... 阅读全文
posted @ 2015-01-25 09:55 江南第一少 阅读(124) 评论(0) 推荐(0)
摘要: 跟3 Sum几乎一样,当时好像故意留着不做的。今天是2014年12月30日,终于把leetcode里面所有medium和hard(不含上锁的几道题)全部刷了一遍!总共130道整。其间感恩节那一个星期生啃了20多道题,然后似乎就慢慢找到感觉了,最高纪录一天刷了10题。万里长征走了第一步,不管怎样,这第... 阅读全文
posted @ 2014-12-31 12:32 江南第一少 阅读(118) 评论(0) 推荐(0)
摘要: 难点:如何识别循环体?解决方法:用一个HashMap记录每一个余数,当出现重复的余数时,那么将会进入循环,两个重复余数之间的部分就是循环体。示例:1/13=0.076923076923076923...,当小数部分第二次出现0时,就意味着开始了循环,那么需要把076923用括号括起来,结果为0.(0... 阅读全文
posted @ 2014-12-31 11:58 江南第一少 阅读(118) 评论(0) 推荐(0)
摘要: 题目大意:给定一个未排序的数组,找出其排序后的序列中两个相邻元素之间的最大差值。最好在线性时间、线性空间复杂度内完成。如果数组少于2个元素,返回0。可以假设数组中的所有元素均为非负整数,并且在32位带符号整数的范围以内。解题思路:基数排序(radix sort)/桶排序(bucket sort)官方... 阅读全文
posted @ 2014-12-31 11:06 江南第一少 阅读(165) 评论(0) 推荐(0)
摘要: A peak element is an element that is greater than its neighbors.Given an input array wherenum[i] ≠ num[i+1], find a peak element and return its index.... 阅读全文
posted @ 2014-12-31 09:08 江南第一少 阅读(187) 评论(0) 推荐(0)
摘要: 参考之前做的Search In Rotated Sorted Array,与之前略有不一样的是要多传一个min。public class Solution { public int findMin(int[] num) { if(num == null || num.length... 阅读全文
posted @ 2014-12-30 13:22 江南第一少 阅读(122) 评论(0) 推荐(0)