摘要: 最近在刷leetcode,发现很多题目的思路都很相似。其中,collections模块中的Counter()多次在习题中碰到,很有必要对该知识点总结一下,加深理解。 1.collections模块 collections模块自Python 2.4 版本之后,引入除了dict、list、set、tup 阅读全文
posted @ 2017-09-23 16:30 Yancea 阅读(458) 评论(0) 推荐(0) 编辑
摘要: Given a non-empty array of integers, return the k most frequent elements. For example,Given [1,1,1,2,2,3] and k = 2, return [1,2]. Note: You may assum 阅读全文
posted @ 2017-09-23 15:57 Yancea 阅读(157) 评论(0) 推荐(0) 编辑
摘要: Given an integer array with no duplicates. A maximum tree building on this array is defined as follow: Construct the maximum tree by the given array a 阅读全文
posted @ 2017-09-22 14:40 Yancea 阅读(115) 评论(0) 推荐(0) 编辑
摘要: Given the root of a tree, you are asked to find the most frequent subtree sum. The subtree sum of a node is defined as the sum of all the node values 阅读全文
posted @ 2017-09-20 20:35 Yancea 阅读(136) 评论(2) 推荐(0) 编辑
摘要: In English, we have a concept called root, which can be followed by some other words to form another longer word - let's call this word successor. For 阅读全文
posted @ 2017-09-16 16:50 Yancea 阅读(125) 评论(0) 推荐(0) 编辑
摘要: Given a non negative integer number num. For every numbers i in the range 0 ≤ i ≤ num calculate the number of 1's in their binary representation and r 阅读全文
posted @ 2017-09-15 17:06 Yancea 阅读(163) 评论(0) 推荐(0) 编辑
摘要: Given a binary tree, find the leftmost value in the last row of the tree. Example 1: Example 2: Note: You may assume the tree (i.e., the given root no 阅读全文
posted @ 2017-09-15 16:28 Yancea 阅读(103) 评论(0) 推荐(0) 编辑
摘要: You need to find the largest value in each row of a binary tree. Example: 阅读全文
posted @ 2017-09-14 15:59 Yancea 阅读(124) 评论(0) 推荐(0) 编辑
摘要: Suppose you have N integers from 1 to N. We define a beautiful arrangement as an array that is constructed by these N numbers successfully if one of t 阅读全文
posted @ 2017-09-14 14:44 Yancea 阅读(136) 评论(0) 推荐(0) 编辑
摘要: A sequence of number is called arithmetic if it consists of at least three elements and if the difference between any two consecutive elements is the 阅读全文
posted @ 2017-09-13 20:10 Yancea 阅读(178) 评论(0) 推荐(0) 编辑