随笔分类 - LeetCode
OJ
摘要:Related to questionExcel Sheet Column TitleGiven a column title as appear in an Excel sheet, return its corresponding column number.For example: A ...
阅读全文
摘要:Given a positive integer, return its corresponding column title as appear in an Excel sheet.For example: 1 -> A 2 -> B 3 -> C ... 26 ->...
阅读全文
摘要:Given an unsorted array, find the maximum difference between the successive elements in its sorted form.Try to solve it in linear time/space.Return 0 ...
阅读全文
摘要:Compare two version numbersversion1andversion2.Ifversion1>version2return 1, ifversion1 string2Ints(const string& str) { vector rtn; ...
阅读全文
摘要:桶排序,由于num中的数字肯定在[min,max]区间内,所以根据抽屉原理,假设num中有n个数字,则最大的gap必然要大于dis=(max-min)/(n-1),所以我们可以把num所在的范围分成等间隔的区间,相邻区间内的元素之间的最大差值,即为要寻找的gap。TODO
阅读全文
摘要:A peak element is an element that is greater than its neighbors.Given an input array wherenum[i] ≠ num[i+1], find a peak element and return its index....
阅读全文
摘要:Write a program to find the node at which the intersection of two singly linked lists begins.For example, the following two linked lists:A: a...
阅读全文
摘要:Design a stack that supports push, pop, top, and retrieving the minimum element in constant time.push(x) -- Push element x onto stack.pop() -- Removes...
阅读全文
摘要:Given an input string, reverse the string word by word.For example,Given s = "the sky is blue",return "blue is sky the".Update (2015-02-12):For C prog...
阅读全文
摘要:Evaluate the value of an arithmetic expression inReverse Polish Notation.Valid operators are+,-,*,/. Each operand may be an integer or another express...
阅读全文
摘要:Given a binary search tree, write a functionkthSmallestto find thekth smallest element in it.Note:You may assume k is always valid, 1 ≤ k ≤ BST's tota...
阅读全文
摘要:Given an integer, write a function to determine if it is a power of two.Credits:Special thanks to@jianchao.li.fighterfor adding this problem and creat...
阅读全文
摘要:Givennpoints on a 2D plane, find the maximum number of points that lie on the same straight line.Hide TagsHash TableMath给出平面上的点,问一条直线最多穿过几个点.要不是之前看过这个...
阅读全文
摘要:Sort a linked list using insertion sort.Hide TagsLinked ListSort分析:把链表分成两部分:排好序的和为排序的,排好序的以NULL结尾,cur插在preInsertion和insertion之间,next保存cur->next. 另外...
阅读全文
摘要:Design and implement a data structure for Least Recently Used (LRU) cache. It should support the following operations:getandset.get(key)- Get the valu...
阅读全文
摘要:Given 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' values.For exam...
阅读全文
摘要:Given a linked list, return the node where the cycle begins. If there is no cycle, returnnull.Follow up:Can you solve it without using extra space?Hid...
阅读全文
摘要:Given a linked list, determine if it has a cycle in it.Follow up:Can you solve it without using extra space?Hide TagsLinked ListTwo Pointers分析:经典的快慢指针...
阅读全文
摘要:Given a binary tree, imagine yourself standing on therightside of it, return the values of the nodes you can see ordered from top to bottom.For exampl...
阅读全文
摘要:Follow upfor "Find Minimum in Rotated Sorted Array":What ifduplicatesare allowed?Would this affect the run-time complexity? How and why?Suppose a sort...
阅读全文