码迷,mamicode.com
首页 >  
搜索关键字:leetcode 19    ( 34993个结果
LeetCode-003 Longest Substring Without Repeating Characters
【题目】 Given a string, find the length of the longest substring without repeating characters. For example, the longest substring without repeating letters for "abcabcbb" is "abc", which the length is 3. For "bbbbb" the longest substring is "b", with the len...
分类:其他好文   时间:2014-05-15 14:40:14    阅读次数:320
Leetcode--Validate Binary Search Tree
Problem Description: 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 nodes with keys l...
分类:其他好文   时间:2014-05-15 11:22:21    阅读次数:317
Leetcode 树 Unique Binary Search TreesII
本文为senlie原创,转载请保留此地址:http://blog.csdn.net/zhengsenlie Unique Binary Search Trees II  Total Accepted: 7349 Total Submissions: 27648 Given n, generate all structurally unique ...
分类:其他好文   时间:2014-05-15 07:02:36    阅读次数:252
Leetcode 线性表 Linked List Cycle
题意:判断一个链表中是否有环 思路:快慢指针,如果有环,最终快慢指针会在非NULL相遇 注:用到fast->next前先要确保fast非NULL,要用fast->next->next前先要确保fast,fast->next非NULL 复杂度:时间O(n), 空间O(1) 相关题目:Linked List CycleII...
分类:其他好文   时间:2014-05-15 07:01:57    阅读次数:219
Leetcode 树 Binary Tree Inorder Traversal
题意:中序遍历 思路:采用递归实现。因为函数声明是返回一个vector,所以每个子树返回的是该子树的中序遍历的结果 按照 左、根、右的次序把根和左右子树的vector合并起来就可以了...
分类:其他好文   时间:2014-05-15 06:21:09    阅读次数:255
leetcode第一刷_Jump Game II
要求最小的步数,是不是很容易想到用dp啊? 我一开始的做法是,当找到了一个可以从它延伸到更远的位置,就把这个位置和最远位置的步数都更新一下,结果超时了。其实这样不仅是超时的,而且是错误的。因为这段距离里的很多点,其实是上一步就能到达的。其实应该更新的只有哪些新的能够到达的点,那哪些点是新的能到达的点呢?假设这次能够延伸更远的点是i,它的前进步数是A[i],上一次能够到达的最远的点是mmax,那新...
分类:其他好文   时间:2014-05-15 05:54:41    阅读次数:229
leetcode第一刷_Permutations II
当有重复元素的时候呢? 不用拍脑袋都会想到一种方法,也是所有有重复元素时的通用处理方法,维护一个set,如果这个元素没加入过就加入,加入过了的忽略掉。但是,在这道题上这个通用方法居然超时了! 怎么办?想一下为什么会这样,假设我们要排列的数字是1111112,当当前的排列中没有1时,取哪个1生成一遍,都是一样的。只有当前面的1都用过了,必须轮到这个1出场的时候,它才会有价值。更明确一点说,假设我...
分类:其他好文   时间:2014-05-15 05:36:25    阅读次数:198
[LeetCode] K sum(2Sum、3Sum、4Sum)
2Sum & 3Sum & 4Sum & KSum...
分类:其他好文   时间:2014-05-15 05:33:56    阅读次数:270
[LeetCode]ZigZag Conversion
Write the code that will take a string and make this conversion given a number of rows: P A H N A P L S I I G Y I R convert("PAYPALISHIRING", 3) should return "PAHNAPLSIIGYIR"....
分类:其他好文   时间:2014-05-15 04:49:04    阅读次数:311
leetCode-002 Median of Two Sorted Arrays
leetCode-002 Median of Two Sorted Arrays 【题目】 There are two sorted arrays A and B of size m and n respectively. Find the median of the two sorted arrays. The overall run time complexity should be O(log (m+n)). 【题意】 有两个有序的数组,找出这两数组整合后的中位数,要求时间复杂度O(nlogn)...
分类:其他好文   时间:2014-05-15 04:42:05    阅读次数:274
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!