从给定的有序链表生成一颗平衡二叉树。
解题思路:最容易想到的就是利用数组生成二叉树的方法,找到中间节点作为二叉树的root节点,然后分别对左右链表递归调用分别生成左子树和右子树。时间复杂度O(N*lgN)...
分类:
其他好文 时间:
2014-10-01 23:36:31
阅读次数:
243
Given a string containing just the characters '(' and ')', find the length of the longest valid (well-formed) parentheses substring.
For "(()", the longest valid parentheses substring is "()", which ...
分类:
其他好文 时间:
2014-09-22 03:21:11
阅读次数:
264
Construct Binary Tree from Preorder and Inorder Traversal 结题报告
从前序遍历和中序遍历的结果重建一颗二叉树。
解题思路,随便写一个二叉树,然后写出前序和中序遍历的结果会发现特点。
二叉树的首节点必然是前序遍历的第一个节点,以这个节点在中序遍历的结果中作为划分,这个节点左侧的是左子树的节点,右侧是右子树节点。
例如,一个二叉...
分类:
其他好文 时间:
2014-09-14 20:48:47
阅读次数:
176
题目一:Longest Substring Without Repeating CharactersGiven a string, find the length of the longest substring without repeating characters. For example, ...
分类:
其他好文 时间:
2014-07-22 23:04:12
阅读次数:
246
Reorder ListGiven a singly linked listL: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' val...
分类:
其他好文 时间:
2014-06-28 20:42:16
阅读次数:
265
Linked List CycleGiven a linked list, determine if it has a cycle in it.Follow up:Can you solve it without using extra space?Linked List Cycle IIGiven...
分类:
其他好文 时间:
2014-06-20 20:46:58
阅读次数:
245
Given a binary tree, return thepostordertraversal of its nodes' values.For example:Given binary tree{1,#,2,3}, 1 \ 2 / 3return[3,2,1].No...
分类:
其他好文 时间:
2014-06-18 17:32:02
阅读次数:
168
Insertion Sort ListSort a linked list using
insertion sort. leetcode
subject思路:标准的插入排序。考察一下链表的操作。对链表进行插入排序的正确方法是:新建一个头节点,遍历原来的链表,对原链表的每个节点找到新链表中适合插入位置...
分类:
其他好文 时间:
2014-06-16 00:34:07
阅读次数:
364
LRU CacheDesign and implement a data structure for Least Recently Used (LRU) cache. It should support the following operations:getandset.get(key)- Get...
分类:
其他好文 时间:
2014-06-14 23:54:37
阅读次数:
352
题目
Given an array S of n integers, are there elements a, b, c in S such that a + b + c = 0? Find all unique triplets in the array which gives the sum of zero.
Note:
Elements in a triplet (a,b,c) ...
分类:
其他好文 时间:
2014-06-14 12:45:13
阅读次数:
209