09 2017 档案

摘要:最近在刷leetcode,发现很多题目的思路都很相似。其中,collections模块中的Counter()多次在习题中碰到,很有必要对该知识点总结一下,加深理解。 1.collections模块 collections模块自Python 2.4 版本之后,引入除了dict、list、set、tup 阅读全文
posted @ 2017-09-23 16:30 Yancea 阅读(479) 评论(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 阅读(165) 评论(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 阅读(121) 评论(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 阅读(145) 评论(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 阅读(133) 评论(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 阅读(176) 评论(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 阅读(109) 评论(0) 推荐(0)
摘要:You need to find the largest value in each row of a binary tree. Example: 阅读全文
posted @ 2017-09-14 15:59 Yancea 阅读(131) 评论(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 阅读(144) 评论(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 阅读(194) 评论(0) 推荐(0)
摘要:Given a sorted array consisting of only integers where every element appears twice except for one element which appears once. Find this single element 阅读全文
posted @ 2017-09-13 18:59 Yancea 阅读(167) 评论(0) 推荐(0)
摘要:Given a binary tree, return the tilt of the whole tree. The tilt of a tree node is defined as the absolute difference between the sum of all left subt 阅读全文
posted @ 2017-09-13 18:23 Yancea 阅读(105) 评论(0) 推荐(0)
摘要:Find the sum of all left leaves in a given binary tree. Example: 3 / \ 9 20 / \ 15 7 There are two left leaves in the binary tree, with values 9 and 1 阅读全文
posted @ 2017-09-12 23:35 Yancea 阅读(84) 评论(0) 推荐(0)
摘要:Given an array of integers that is already sorted in ascending order, find two numbers such that they add up to a specific target number. The function 阅读全文
posted @ 2017-09-12 16:11 Yancea 阅读(133) 评论(0) 推荐(0)
摘要:Given a Binary Search Tree and a target number, return true if there exist two elements in the BST such that their sum is equal to the given target. E 阅读全文
posted @ 2017-09-12 15:28 Yancea 阅读(162) 评论(0) 推荐(0)
摘要:Say you have an array for which the ith element is the price of a given stock on day i. Design an algorithm to find the maximum profit. You may comple 阅读全文
posted @ 2017-09-12 15:11 Yancea 阅读(146) 评论(0) 推荐(0)
摘要:Assume you are an awesome parent and want to give your children some cookies. But, you should give each child at most one cookie. Each child i has a g 阅读全文
posted @ 2017-09-12 14:23 Yancea 阅读(137) 评论(0) 推荐(0)
摘要:Given an arbitrary ransom note string and another string containing letters from all the magazines, write a function that will return true if the rans 阅读全文
posted @ 2017-09-12 10:54 Yancea 阅读(159) 评论(0) 推荐(0)
摘要:Given a table salary, such as the one below, that has m=male and f=female values. Swap all f and m values (i.e., change all f values to m and vice ver 阅读全文
posted @ 2017-09-11 22:38 Yancea 阅读(153) 评论(0) 推荐(0)
摘要:Given an array of 2n integers, your task is to group these integers into n pairs of integer, say (a1, b1), (a2, b2), ..., (an, bn) which makes sum of 阅读全文
posted @ 2017-09-11 22:34 Yancea 阅读(131) 评论(0) 推荐(0)
摘要:Given two binary trees and imagine that when you put one of them to cover the other, some nodes of the two trees are overlapped while the others are n 阅读全文
posted @ 2017-09-11 22:29 Yancea 阅读(133) 评论(0) 推荐(0)
摘要:The Hamming distance between two integers is the number of positions at which the corresponding bits are different. Given two integers x and y, calcul 阅读全文
posted @ 2017-09-11 22:24 Yancea 阅读(109) 评论(0) 推荐(0)
摘要:There is a table World A country is big if it has an area of bigger than 3 million square km or a population of more than 25 million. Write a SQL solu 阅读全文
posted @ 2017-09-11 22:21 Yancea 阅读(120) 评论(0) 推荐(0)
摘要:Given a binary search tree and the lowest and highest boundaries as L and R, trim the tree so that all its elements lies in [L, R] (R >= L). You might 阅读全文
posted @ 2017-09-11 19:57 Yancea 阅读(111) 评论(0) 推荐(0)
摘要:Given a positive integer, return its corresponding column title as appear in an Excel sheet. For example: 阅读全文
posted @ 2017-09-11 19:03 Yancea 阅读(133) 评论(0) 推荐(0)
摘要:Given a column title as appear in an Excel sheet, return its corresponding column number. For example: 相关问题:http://www.cnblogs.com/yancea/p/7506456.ht 阅读全文
posted @ 2017-09-11 12:20 Yancea 阅读(106) 评论(0) 推荐(0)
摘要:Given two arrays, write a function to compute their intersection. Example:Given nums1 = [1, 2, 2, 1], nums2 = [2, 2], return [2]. Note: Each element i 阅读全文
posted @ 2017-09-08 16:36 Yancea 阅读(112) 评论(0) 推荐(0)
摘要:Given a non-empty integer array of size n, find the minimum number of moves required to make all array elements equal, where a move is incrementing n  阅读全文
posted @ 2017-09-08 16:06 Yancea 阅读(111) 评论(0) 推荐(0)
摘要:Initially, there is a Robot at position (0, 0). Given a sequence of its moves, judge if this robot makes a circle, which means it moves back to the or 阅读全文
posted @ 2017-09-08 15:18 Yancea 阅读(180) 评论(0) 推荐(0)