随笔分类 -  算法

Max Points on a Line
摘要:Given n points on a 2D plane, find the maximum number of points that lie on the same straight line.##思路关键是浮点数做key不靠谱,struct hash以及 int calcGCD(int a, ... 阅读全文

posted @ 2014-09-20 10:37 小唯THU 阅读(451) 评论(0) 推荐(0)

【并查集】【树】最近公共祖先LCA-Tarjan算法
摘要:[最近公共祖先LCA](https://github.com/julycoding/The-Art-Of-Programming-By-July/blob/master/ebook/zh/03.03.md)##双链BT如果每个结点都有一个指针指向它的父结点,于是我们可以从任何一个结点出发,得到一个到... 阅读全文

posted @ 2014-08-24 20:31 小唯THU 阅读(2192) 评论(0) 推荐(0)

【Stack】Evaluate Reverse Polish Notation
摘要:Evaluate the value of an arithmetic expression inReverse Polish Notation.Valid operators are+,-,*,/. Each operand may be an integer or another ex... 阅读全文

posted @ 2014-08-22 00:24 小唯THU 阅读(194) 评论(0) 推荐(0)

时针和分针每天重合多少次
摘要:如果不假思索地脱口而出24次,你就被直觉骗了咯 阅读全文

posted @ 2014-08-20 21:56 小唯THU 阅读(10426) 评论(9) 推荐(3)

【DP】【String】Palindrome Partitioning
摘要:Given a string s, partition s such that every substring of the partition is a palindrome. 阅读全文

posted @ 2014-07-21 20:57 小唯THU 阅读(166) 评论(0) 推荐(0)

【DFS】【Matrix】Word Search
摘要:Given a 2D board and a word, find if the word exists in the grid. 阅读全文

posted @ 2014-07-21 19:50 小唯THU 阅读(185) 评论(0) 推荐(0)

【Sorting】【Linked List】Sort List
摘要:Sort a linked list in O(n log n) time using constant space complexity. 阅读全文

posted @ 2014-07-20 00:30 小唯THU 阅读(396) 评论(0) 推荐(0)

【Sorting】【Array】Find reverse pair in an/two array(s)
摘要:在数组中的两个数字,如果前面一个数字大于后面的数字,则这两个数字组成一个逆序对。输入一个数组,求出这个数组中的逆序对的总数。 阅读全文

posted @ 2014-07-16 21:49 小唯THU 阅读(389) 评论(0) 推荐(0)

【Sorting】【Linked List】Merge k Sorted Lists
摘要:Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity. 阅读全文

posted @ 2014-07-15 10:42 小唯THU 阅读(291) 评论(0) 推荐(0)

【数组】【Prime and composite numbers】Flags
摘要:Find the maximum number of flags that can be set on mountain peaks. 阅读全文

posted @ 2014-07-05 11:44 小唯THU 阅读(400) 评论(0) 推荐(0)

【数组】【Prime and composite numbers】Peaks
摘要:Divide an array into the maximum number of same((-))sized blocks, each of which should contain an index P such that A[P - 1] A[P + 1]. 阅读全文

posted @ 2014-07-05 10:14 小唯THU 阅读(507) 评论(0) 推荐(0)

【数组】【DP】Best Time to Buy and Sell Stock
摘要:Given a log of stock prices compute the maximum possible earning. 阅读全文

posted @ 2014-07-04 17:17 小唯THU 阅读(426) 评论(0) 推荐(0)

【数组】【DP】MaxSliceSum & MaxDoubleSliceSum
摘要:Find a maximum sum of a compact subsequence of array elements and any double slice. 阅读全文

posted @ 2014-07-04 16:42 小唯THU 阅读(848) 评论(0) 推荐(0)

【数组】【Prefix Sums】CountDiv
摘要:Write a function:int solution(int A, int B, int K);that, given three integers A, B and K, returns the number of integers within the range [A..B] that ... 阅读全文

posted @ 2014-07-03 22:17 小唯THU 阅读(603) 评论(0) 推荐(0)

【数组】Median of Two Sorted Arrays
摘要:####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 overa... 阅读全文

posted @ 2014-05-22 10:54 小唯THU 阅读(257) 评论(0) 推荐(0)

【题解】【数组】【Leetcode】Gas Station
摘要:There areNgas stations along a circular route, where the amount of gas at stationiisgas[i].You have a car with an unlimited gas tank and it costscost[... 阅读全文

posted @ 2014-02-27 11:22 小唯THU 阅读(324) 评论(0) 推荐(0)

【题解】【数组】【堆栈】【Codility】Fish
摘要:N voracious fish are moving along a river. Calculate how many fish are alive.You are given two non-empty zero-indexed arrays A and B consisting of N i... 阅读全文

posted @ 2014-02-26 11:39 小唯THU 阅读(1186) 评论(0) 推荐(0)

【题解】【直方图】【堆栈】【Codility】StoneWall
摘要:Cover "Manhattan skyline" using the minimum number of rectangles.You are going to build a stone wall. The wall should be straight and N meters long, a... 阅读全文

posted @ 2014-02-25 11:36 小唯THU 阅读(1681) 评论(0) 推荐(0)

【题解】【数组】【Leader】【Codility】Dominator&Equi-leader
摘要:Find an index of an array such that its value occurs at more than half of indices in the array.A zero-indexed array A consisting of N integers is give... 阅读全文

posted @ 2014-02-23 21:45 小唯THU 阅读(1075) 评论(0) 推荐(0)

【题解】【区间】【Sorting】【Codility】Number of disc intersections
摘要:Given an array A of N integers, we draw N discs in a 2D plane such that the I-th disc is centered on (0,I) and has a radius of A[I]. We say that the J... 阅读全文

posted @ 2014-02-22 17:09 小唯THU 阅读(1869) 评论(0) 推荐(0)

导航