摘要: You are given a string,S, and a list of words,L, that are all of the same length. Find all starting indices of substring(s) in S that is a concatenation of each word in L exactly once and without any intervening characters.For example, given:S:"barfoothefoobarman"L:["foo", " 阅读全文
posted @ 2013-09-23 07:55 LEDYC 阅读(261) 评论(0) 推荐(1)
摘要: Implement next permutation, which rearranges numbers into the lexicographically next greater permutation of numbers.If such arrangement is not possible, it must rearrange it as the lowest possible order (ie, sorted in ascending order).The replacement must be in-place, do not allocate extra memory.He 阅读全文
posted @ 2013-09-23 05:53 LEDYC 阅读(167) 评论(0) 推荐(1)
摘要: Given a stringSand a stringT, count the number of distinct subsequences ofTinS.A subsequence of a string is a new string which is formed from the original string by deleting some (can be none) of the characters without disturbing the relative positions of the remaining characters. (ie,"ACE" 阅读全文
posted @ 2013-09-23 04:34 LEDYC 阅读(250) 评论(0) 推荐(1)
摘要: Given a binary tree, flatten it to a linked list in-place.For example,Given 1 / \ 2 5 / \ \ 3 4 6The flattened tree should look like: 1 \ 2 \ 3 \ 4 \ 5 \ 6click to show hints.---/** * D... 阅读全文
posted @ 2013-09-23 04:17 LEDYC 阅读(143) 评论(0) 推荐(1)
摘要: Given a binary tree, find its minimum depth.The minimum depth is the number of nodes along the shortest path from the root node down to the nearest leaf node.---/** * Definition for binary tree * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) ... 阅读全文
posted @ 2013-09-23 03:45 LEDYC 阅读(156) 评论(0) 推荐(1)
摘要: 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 subtrees ofeverynode never differ by more than 1.---/** * Definition for binary tree * public class TreeNode { * int val; * TreeNo... 阅读全文
posted @ 2013-09-23 03:32 LEDYC 阅读(169) 评论(0) 推荐(1)
摘要: Given a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST.---需要总长度,遍历一遍,1. 可以再这个时候吧list转成array, 费地方2. 或者跟array一样每次走半个长度找到mid, O(NlogN), logN层,每层遍历N,费时间/** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode n... 阅读全文
posted @ 2013-09-23 02:57 LEDYC 阅读(184) 评论(0) 推荐(1)
摘要: Given an array where elements are sorted in ascending order, convert it to a height balanced BST.---/** * Definition for binary tree * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) { val = x; } * } */public class Solution { public TreeNode... 阅读全文
posted @ 2013-09-23 02:53 LEDYC 阅读(121) 评论(0) 推荐(1)
摘要: Given a binary tree, return thebottom-up level ordertraversal of its nodes' values. (ie, from left to right, level by level from leaf to root).For example:Given binary tree{3,9,20,#,#,15,7}, 3 / \ 9 20 / \ 15 7return its bottom-up level order traversal as:[ [15,7] [9,20], [3],]conf... 阅读全文
posted @ 2013-09-23 02:42 LEDYC 阅读(139) 评论(0) 推荐(1)