Design and implement a data structure for Least
Recently Used (LRU) cache. It should support the following
operations:getandset.get(key)- Get the valu...
分类:
其他好文 时间:
2014-05-23 09:59:05
阅读次数:
257
这道题本来思路并不复杂,先对第一列做binary search,
找到target所在的行,再对所在的行做binary
search,找到target在或不在。但是我在编程的时候遇到了很多问题,堆栈溢出(StackOverflowError)折腾死我了,一些边界条件的考虑也颇费周折。我之所以会碰到堆...
分类:
其他好文 时间:
2014-05-23 08:35:31
阅读次数:
294
用了DP的方法,还有hashtable 1 import java.util.*; 2 3
public class Solution { 4 public int climbStairs(int n) { 5 Hashtable table =
new Hashtable...
分类:
其他好文 时间:
2014-05-23 08:31:02
阅读次数:
234
一次过,空间复杂度为O(m+n), 下一次做的时候寻找constant space
solution。用boolean array也可以,用bit vector可能会更节省 1 import java.util.*; 2 3 public
class Solution { 4 public...
分类:
其他好文 时间:
2014-05-23 08:30:28
阅读次数:
278
1、
??
Balanced Binary Tree
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 depth of the two subt...
分类:
其他好文 时间:
2014-05-23 08:19:19
阅读次数:
282
上得厅堂,下得厨房,写得代码,翻得围墙,欢迎来到睿不可挡的每日一小练!...
分类:
其他好文 时间:
2014-05-22 11:42:14
阅读次数:
253
问题描述
对一个单链表进行插入排序,head指向第一个结点。
代码
/**
* Definition for singly-linked list.
* struct ListNode {
* int val;
* ListNode *next;
* ListNode(int x) : val(x), next(NULL) {}
* };
*/...
分类:
其他好文 时间:
2014-05-22 10:15:43
阅读次数:
233
问题
Given a singly linked list L: L0→L1→…→Ln-1→Ln,
reorder it to: L0→Ln→L1→Ln-1→L2→Ln-2→…
You must do this in-place without altering the nodes' values.
For example,
Given {1,2,3,4}, reorde...
分类:
其他好文 时间:
2014-05-22 07:04:46
阅读次数:
298
class Solution {public: int maxProfit(vector
&prices) { int len = prices.size(); if (len maxv) { maxv = cur; ...
分类:
其他好文 时间:
2014-05-22 05:09:49
阅读次数:
256
5道题目分别是:【Combinations】、【Search a 2D Matrix】、【Scramble String 】、【Rotate List 】、【Partition List】,由于有一些题目不需要发一整篇博文来记录,所以就将这些题目以一篇博文5道来记录。...
分类:
其他好文 时间:
2014-05-20 15:36:16
阅读次数:
293