
leetcode
cainiaohudi
这个作者很懒,什么都没留下…
展开
-
Leetcode 232. Implement Queue using Stacks
这道题的意思是用堆栈来实现队列,pop和peak是去除和获取最前面的元素。下面就是我用python通过的代码class MyQueue(object): def __init__(self): """ Initialize your data structure here. """ self.stack = [] ...原创 2018-04-09 09:30:45 · 134 阅读 · 0 评论 -
leetcode 728. Self Dividing Numbers
class Solution(object): def selfDividingNumbers(self, left, right): """ :type left: int :type right: int :rtype: List[int] """ output = [] f...原创 2018-11-01 09:53:05 · 227 阅读 · 0 评论 -
leetcode 929. Unique Email Addresses
class Solution(object): def numUniqueEmails(self, email): """ :type emails: List[str] :rtype: int """ result = [] for i in range(len(email)): ...原创 2018-10-31 10:21:56 · 561 阅读 · 0 评论 -
766. Toeplitz Matrix
A matrix is Toeplitz if every diagonal from top-left to bottom-right has the same element.Now given an M x N matrix, return True if and only if the matrix is Toeplitz.Example 1:Input: matrix = ...原创 2018-09-04 15:31:51 · 151 阅读 · 0 评论 -
leetcode 347. Top K Frequent Elements
def topKFrequent(self, nums, k): """ :type nums: List[int] :type k: int :rtype: List[int] """ dict = {} result = [] for i in range(len(n...原创 2018-08-20 21:57:11 · 170 阅读 · 0 评论 -
4. Median of Two Sorted Arrays
我真的没想到我这样写能过,本以为会超过他要求的时间复杂度class Solution: def findMedianSortedArrays(self, nums1, nums2): """ :type nums1: List[int] :type nums2: List[int] :rtype: float ...原创 2018-08-22 20:19:32 · 130 阅读 · 0 评论 -
leetcode 435. Non-overlapping Intervals
借鉴了别人的代码,写成javapackage leetcode;import java.util.Arrays;import java.util.Comparator;class Interval { int start; int end; Interval() { start = 0; end = 0; } Interval(int s, int e...原创 2018-04-17 15:36:50 · 252 阅读 · 0 评论 -
leetcode 804. Unique Morse Code Words
本题用到Python基本数据类型set,set是一个无序且不重复的元素集合。class Solution(object): def uniqueMorseRepresentations(self, words): """ :type words: List[str] :rtype: int """ Mors...原创 2018-04-10 09:11:29 · 122 阅读 · 0 评论 -
747. Largest Number At Least Twice of Others
In a given integer array nums, there is always exactly one largest element.Find whether the largest element in the array is at least twice as much as every other number in the array.If it is, return...原创 2018-12-05 21:39:44 · 284 阅读 · 0 评论