码迷,mamicode.com
首页 >  
搜索关键字:leetcode happy numbe    ( 36157个结果
【LeetCode】LRU Cache
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
Leetcode: Search a 2D Matrix
这道题本来思路并不复杂,先对第一列做binary search, 找到target所在的行,再对所在的行做binary search,找到target在或不在。但是我在编程的时候遇到了很多问题,堆栈溢出(StackOverflowError)折腾死我了,一些边界条件的考虑也颇费周折。我之所以会碰到堆...
分类:其他好文   时间:2014-05-23 08:35:31    阅读次数:294
Leetcode: Climbing Stairs
用了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
Leetcode: Set Matrix Zeroes
一次过,空间复杂度为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
替换空格--《剑指offer》
如题所示,题目很简单,替换空格,将字符串中的空格替换为%20; 即"we are happy”替换成“we%20are%20happy”; 如果每当我们遇到一个空格就将字符串向后平移两位,这样复杂度就是O(n2)了,这样的方法是不可取的,按照作者的来说,offer已不足拿到了; 而当我们反向从字符串末尾开始遍历,复杂度仅为O(n),当然前提的是该字符串有足够空间,否则替换会失败。 了解到思想之后程序也就比较简单了,发现自己的与作者的写的也比较类似,就此贴上了......
分类:其他好文   时间:2014-05-22 12:25:54    阅读次数:201
leetcode:Insert Sort List
问题描述 对一个单链表进行插入排序,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
LeetCode Best Time to Buy and Sell Stock
class Solution {public: int maxProfit(vector &prices) { int len = prices.size(); if (len maxv) { maxv = cur; ...
分类:其他好文   时间:2014-05-22 05:09:49    阅读次数:256
【Leetcode】Partition List
Given a linked list and a valuex, partition it such that all nodes less thanxcome before nodes greater than or equal tox.You should preserve the origi...
分类:其他好文   时间:2014-05-22 03:53:29    阅读次数:313
LRU的C++实现引申出的迭代器问题
leetcode上刷题。碰到一题实现LRU算法的题目。LRU,Least recently used。是一种常见的cache和页面替换算法。算法和原理可以参阅相关wiki。leetcode上的这一题,时间要求很苛刻,如果达不到O(1)复杂度的话,基本上会TLE。所以,这一题如果用C++来解的话,需要...
分类:编程语言   时间:2014-05-22 03:34:16    阅读次数:353
leetCode解题报告5道题(九)
5道题目分别是:【Combinations】、【Search a 2D Matrix】、【Scramble String 】、【Rotate List 】、【Partition List】,由于有一些题目不需要发一整篇博文来记录,所以就将这些题目以一篇博文5道来记录。...
分类:其他好文   时间:2014-05-20 15:36:16    阅读次数:293
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!