随笔分类 -  Algorithm

上一页 1 2 3 4 5 6 7 ··· 14 下一页

[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 阅读(484) 评论(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)

[LintCode] Find the Weak Connected Component in the Directed Graph
摘要:Find the Weak Connected Component in the Directed GraphFind the number Weak Connected Component in the directed graph. Each node in the graph contains... 阅读全文

posted @ 2015-06-29 13:34 Eason Liu 阅读(1436) 评论(0) 推荐(0)

[LeetCode] Majority Element II
摘要:Majority Element IIGiven an integer array of sizen, find all elements that appear more than⌊ n/3 ⌋times. The algorithm should run in linear time and i... 阅读全文

posted @ 2015-06-29 10:44 Eason Liu 阅读(269) 评论(0) 推荐(0)

[LintCode] Find the Connected Component in the Undirected Graph
摘要:Find the Connected Component in the Undirected GraphFind the number connected component in the undirected graph. Each node in the graph contains a lab... 阅读全文

posted @ 2015-06-28 22:37 Eason Liu 阅读(1347) 评论(0) 推荐(1)

[hihoCoder] 第五十二周: 连通性·一
摘要:题目1 : 连通性·一时间限制:10000ms单点时限:1000ms内存限制:256MB描述还记得上次小Hi和小Ho学校被黑客攻击的事情么,那一次攻击最后造成了学校网络数据的丢失。为了避免再次出现这样的情况,学校决定对校园网络进行重新设计。学校现在一共拥有N台服务器(编号1..N)以及M条连接,保证... 阅读全文

posted @ 2015-06-27 22:34 Eason Liu 阅读(432) 评论(0) 推荐(0)

[LeetCode] Summary Ranges
摘要:Summary RangesGiven a sorted integer array without duplicates, return the summary of its ranges.For example, given[0,1,2,4,5,7], return["0->2","4->5",... 阅读全文

posted @ 2015-06-26 13:48 Eason Liu 阅读(651) 评论(0) 推荐(0)

[hihoCoder] 第五十周: 欧拉路·二
摘要:题目1 : 欧拉路·二时间限制:10000ms单点时限:1000ms内存限制:256MB描述在上一回中小Hi和小Ho控制着主角收集了分散在各个木桥上的道具,这些道具其实是一块一块骨牌。主角继续往前走,面前出现了一座石桥,石桥的尽头有一道火焰墙,似乎无法通过。小Hi注意到在桥头有一张小纸片,于是控制主... 阅读全文

posted @ 2015-06-21 20:30 Eason Liu 阅读(362) 评论(0) 推荐(0)

上一页 1 2 3 4 5 6 7 ··· 14 下一页