07 2015 档案

[CTCI] 子串判断
摘要:子串判断题目描述现有一个小写英文字母组成的字符串s和一个包含较短小写英文字符串的数组p,请设计一个高效算法,对于p中的每一个较短字符串,判断其是否为s的子串。给定一个string数组p和它的大小n,同时给定strings,为母串,请返回一个bool数组,每个元素代表p中的对应字符串是否为s的子串。保... 阅读全文

posted @ 2015-07-30 21:39 Eason Liu 阅读(542) 评论(0) 推荐(0)

[CTCI] 最大子方阵
摘要:最大子方阵题目描述有一个方阵,其中每个单元(像素)非黑即白(非0即1),请设计一个高效算法,找到四条边颜色相同的最大子方阵。给定一个01方阵mat,同时给定方阵的边长n,请返回最大子方阵的边长。保证方阵变长小于等于100。测试样例:[[1,1,1],[1,0,1],[1,1,1]],3返回:3要看清... 阅读全文

posted @ 2015-07-30 21:27 Eason Liu 阅读(865) 评论(0) 推荐(0)

[LintCode] Number of Islands II
摘要:Number of Islands IIGiven a n,m which means the row and column of the 2D matrix and an array of pair A( size k). Originally, the 2D matrix is all 0 wh... 阅读全文

posted @ 2015-07-28 19:24 Eason Liu 阅读(3205) 评论(0) 推荐(0)

[LeetCode] Different Ways to Add Parentheses
摘要:Different Ways to Add ParenthesesGiven a string of numbers and operators, return all possible results from computing all the different possible ways t... 阅读全文

posted @ 2015-07-27 22:50 Eason Liu 阅读(4033) 评论(0) 推荐(0)

[CTCI] 下一个较大元素
摘要:下一个较大元素题目描述现在我们有一个int数组,请你找出数组中每个元素的下一个比它大的元素。给定一个int数组A及数组的大小n,请返回一个int数组,代表每个元素比他大的下一个元素,若不存在则为-1。保证数组中元素均为正整数。测试样例:[11,13,10,5,12,21,3],7返回:[13,21,... 阅读全文

posted @ 2015-07-26 21:06 Eason Liu 阅读(455) 评论(0) 推荐(0)

[CTCI] 单词最近距离
摘要:单词最近距离题目描述有一篇文章内含多个单词,现给定两个单词,请设计一个高效算法,找出文中这两个单词的最短距离(即最少相隔的单词数,也就是两个单词在文章中位置的差的绝对值)。给定一个string数组article,代表所给文章,同时给定文章的单词数n和待查找的两个单词x和y。请返回两个单词的最短距离。... 阅读全文

posted @ 2015-07-26 14:20 Eason Liu 阅读(426) 评论(0) 推荐(0)

[LeetCode] Sliding Window Maximum
摘要:Sliding Window MaximumGiven an arraynums, there is a sliding window of sizekwhich is moving from the very left of the array to the very right. You can... 阅读全文

posted @ 2015-07-18 18:43 Eason Liu 阅读(314) 评论(0) 推荐(0)

[CTCI] 双栈排序
摘要:双栈排序题目描述请编写一个程序,按升序对栈进行排序(即最大元素位于栈顶),要求最多只能使用一个额外的栈存放临时数据,但不得将元素复制到别的数据结构中。给定一个int[]numbers(C++中为vector),其中第一个元素为栈顶,请返回排序后的栈。请注意这是一个栈,意味着排序过程中你只能访问到第一... 阅读全文

posted @ 2015-07-18 13:50 Eason Liu 阅读(485) 评论(0) 推荐(0)

[LeetCode] Delete Node in a Linked List
摘要:Delete Node in a Linked ListWrite a function to delete a node (except the tail) in a singly linked list, given only access to that node.Supposed the l... 阅读全文

posted @ 2015-07-15 09:20 Eason Liu 阅读(267) 评论(0) 推荐(0)

[MeetCoder] Crossing Bridge
摘要:Crossing BridgeDescriptionN people wish to cross a bridge at night. It’s so dark around there that they have to cross the bridge under the help of a l... 阅读全文

posted @ 2015-07-14 21:06 Eason Liu 阅读(358) 评论(0) 推荐(0)

[LintCode] N-Queens
摘要:N-QueensThe n-queens puzzle is the problem of placing n queens on an n×n chessboard such that no two queens attack each other.Given an integer n, retu... 阅读全文

posted @ 2015-07-14 19:11 Eason Liu 阅读(343) 评论(0) 推荐(0)

[LeetCode] Lowest Common Ancestor of a Binary Tree
摘要:Lowest Common Ancestor of a Binary TreeGiven a binary tree, find the lowest common ancestor (LCA) of two given nodes in the tree.According to thedefin... 阅读全文

posted @ 2015-07-13 20:40 Eason Liu 阅读(4247) 评论(0) 推荐(0)

[LeetCode] Lowest Common Ancestor of a Binary Search Tree
摘要:Lowest Common Ancestor of a Binary Search TreeGiven a binary search tree (BST), find the lowest common ancestor (LCA) of two given nodes in the BST.Ac... 阅读全文

posted @ 2015-07-11 17:27 Eason Liu 阅读(1684) 评论(0) 推荐(0)

[LeetCode] Palindrome Linked List
摘要:Palindrome Linked ListGiven a singly linked list, determine if it is a palindrome.Follow up:Could you do it in O(n) time and O(1) space?将链表拆成两半,后一半反转后... 阅读全文

posted @ 2015-07-11 17:12 Eason Liu 阅读(207) 评论(0) 推荐(0)

[LintCode] Remove Node in Binary Search Tree
摘要:Remove Node in Binary Search TreeGiven a root of Binary Search Tree with unique value for each node. Remove the node with given value. If there is no ... 阅读全文

posted @ 2015-07-09 22:29 Eason Liu 阅读(747) 评论(0) 推荐(0)

[LeetCode] Power of Two
摘要:Power of TwoGiven an integer, write a function to determine if it is a power of two.Credits:Special thanks to@jianchao.li.fighterfor adding this probl... 阅读全文

posted @ 2015-07-06 20:36 Eason Liu 阅读(209) 评论(0) 推荐(0)

[LeetCode] Kth Smallest Element in a BST
摘要:Kth Smallest Element in a BSTGiven a binary search tree, write a functionkthSmallestto find thekth smallest element in it.Note:You may assume k is alw... 阅读全文

posted @ 2015-07-02 14:54 Eason Liu 阅读(1187) 评论(0) 推荐(0)

[MeetCoder] Count Pairs
摘要:Count PairsDescriptionYou are given n circles centered on Y-aixs. The ith circle’s center is at point (i, 0) and its radius is A[i]. Count the number ... 阅读全文

posted @ 2015-07-01 23:27 Eason Liu 阅读(307) 评论(0) 推荐(0)