摘要: 用heap解, 方法1. 维护一个 size = k 的最小堆。当前元如果大于堆顶的元素,那么说明堆顶的元素肯定小于kth largest element。所以replace他。 或者维护一个-nums的最小堆,从heap pop出第k个元素。那么这个数就是 -nums的第k小元素,也就是nums的 阅读全文
posted @ 2017-05-15 11:09 lettuan 阅读(114) 评论(0) 推荐(0) 编辑
摘要: class Solution(object): def multiply(self, num1, num2): """ :type num1: str :type num2: str :rtype: str """ n1 = len(num1) n2 ... 阅读全文
posted @ 2017-05-15 08:51 lettuan 阅读(101) 评论(0) 推荐(0) 编辑
摘要: Say you have an array for which the ith element is the price of a given stock on day i. If you were only permitted to complete at most one transaction 阅读全文
posted @ 2017-05-15 05:14 lettuan 阅读(139) 评论(0) 推荐(0) 编辑
摘要: 求给出的数字串,如果按照电话键盘的编译方式,可以给出多少那些对应的数字组合。例如: 典型的DFS问题。 阅读全文
posted @ 2017-05-14 09:35 lettuan 阅读(168) 评论(0) 推荐(0) 编辑
摘要: Given a binary tree, return the vertical order traversal of its nodes' values. (ie, from top to bottom, column by column). If two nodes are in the sam 阅读全文
posted @ 2017-05-14 09:10 lettuan 阅读(217) 评论(0) 推荐(0) 编辑
摘要: Suppose you are at a party with n people (labeled from 0 to n - 1) and among them, there may exist one celebrity. The definition of a celebrity is tha 阅读全文
posted @ 2017-05-13 04:01 lettuan 阅读(126) 评论(0) 推荐(0) 编辑
摘要: Given an array of meeting time intervals consisting of start and end times [[s1,e1],[s2,e2],...] (si < ei), determine if a person could attend all mee 阅读全文
posted @ 2017-05-13 03:26 lettuan 阅读(346) 评论(0) 推荐(0) 编辑
摘要: Given an array nums and a target value k, find the maximum length of a subarray that sums to k. If there isn't one, return 0 instead. Note: The sum of 阅读全文
posted @ 2017-05-12 23:00 lettuan 阅读(169) 评论(0) 推荐(0) 编辑
摘要: Given a binary tree, return the postorder traversal of its nodes' values. For example:Given binary tree {1,#,2,3}, return [3,2,1]. Note: Recursive sol 阅读全文
posted @ 2017-05-11 03:24 lettuan 阅读(128) 评论(0) 推荐(0) 编辑
摘要: Given a binary tree, collect a tree's nodes as if you were doing this: Collect and remove all leaves, repeat until the tree is empty. Example: Given b 阅读全文
posted @ 2017-05-10 11:25 lettuan 阅读(292) 评论(0) 推荐(0) 编辑