
LEETCODE
TonyYang1995
每天都进步一小点
展开
-
[LEETCODE] 376. Wiggle Subsequence
376.Wiggle Subsequence 解题报告 A sequence of numbers is called a wiggle sequence if the differences between successive numbers strictly alternate between positive and negative. The first difference (if o原创 2016-07-23 20:02:32 · 528 阅读 · 0 评论 -
[leetcode] 368. Largest Divisible Subset
题目链接: https://leetcode.com/problems/largest-divisible-subset/Given a set of distinct positive integers, find the largest subset such that every pair (Si, Sj) of elements in this subset satis转载 2016-07-30 11:53:50 · 433 阅读 · 0 评论 -
[LEETCODE]230. Kth Smallest Element in a BST
Given a binary search tree, write a function kthSmallest to find the kth smallest element in it.Note: You may assume k is always valid, 1 ≤ k ≤ BST’s total elements.Follow up: What if the BST is mod原创 2016-07-30 20:05:20 · 448 阅读 · 0 评论 -
leetcode 375. Guess Number Higher or Lower II
leetcode 375. Guess Number Higher or Lower II原创 2016-07-20 16:59:09 · 567 阅读 · 0 评论 -
[leetcode 583] Delete Operation for Two Strings
Description: Given two words word1 and word2, find the minimum number of steps required to make word1 and word2 the same, where in each step you can delete one character in either string.Example 1: I原创 2017-05-17 16:18:10 · 1109 阅读 · 0 评论 -
Leetcode 394. Decode String
Given an encoded string, return it’s decoded string.The encoding rule is: k[encoded_string], where the encoded_string inside the square brackets is being repeated exactly k times. Note that k is guaran原创 2017-05-18 15:09:26 · 371 阅读 · 0 评论 -
Leetcode 459. Repeated Substring Pattern
Given a non-empty string check if it can be constructed by taking a substring of it and appending multiple copies of the substring together. You may assume the given string consists of lowercase Englis原创 2017-05-19 10:56:02 · 442 阅读 · 0 评论 -
Leetcode 65. Valid Number
判断是否为一个数 注意: 1. .35,00 可以算做小数, 只有一个”.” 不算 2. 要注意 空格 3. 可以有正负号 4. 如果有e 的话,那么一定要是AeB 这样的形式,而且B 是整数, 可以带正负号。 A 可以是整数也可以是小数,带正负号算法就是把字符串分成A 和B 两个子字符串,按照A 和B 的规则是找在discussion 里面看到了一个python的解法:class Sol原创 2017-08-28 23:25:02 · 505 阅读 · 0 评论 -
Leetcode 647. Palindromic Substrings
找到字符串中的回文子序列的个数 比如 给定一个字符串“aaa”, 它的子序列的个数就是 a, a, a, aa, aa, aaa 如果给定的是“abc”, 那么它的子序列就是a, b, cstring[i]到 string[j] 这个子串是回文的可能性只有当 string[i] == string[j] 而且string[i + 1] 到 string[j - 1] 是回文。 但是考虑到如果中间原创 2017-08-29 01:25:03 · 587 阅读 · 0 评论 -
Leetcode amazon 面试题(二)
242. valid anagram给定两个字符串,问是否是 anagram(同字母异序)python 的做法很简单,一行就好了def isAnagram(self, s, t): return sorted(s) == sorted(t)这个是时间复杂度是 O(nlogn)想要提高 速度的话 可以用 hash table用两个list 存每个字符出现次数,然后比较。时间复杂度是O...原创 2018-03-01 09:54:26 · 1070 阅读 · 0 评论 -
Leetcode amazon 面试题系列(一)
最近在刷亚麻的面试题,然后顺便想练一练python的技巧,所以就用python刷了一边。然后mark一下以后可以复习。leetcode 771.大概就是给定两个字符串a 和b,问b 中出现了多少次a 的字符。记录一个python的用法:def numJewelsInStones(self, J, S): return sum(map(J.count, S))这里利用了 python 的几个...原创 2018-02-23 04:54:33 · 5000 阅读 · 0 评论 -
【LEETCODE】328. Odd Even Linked List
Given a singly linked list, group all odd nodes together followed by the even nodes. Please note here we are talking about the node number and not the value in the nodes.You should try to do it in plac原创 2016-07-30 11:36:23 · 388 阅读 · 0 评论 -
leetcode 347. Top K Frequent Elements
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].原创 2016-07-16 11:38:39 · 298 阅读 · 0 评论 -
leetcode 350. Intersection of Two Arrays II
Given two arrays, write a function to compute their intersection.Example: Given nums1 = [1, 2, 2, 1], nums2 = [2, 2], return [2, 2].原创 2016-07-16 10:47:12 · 329 阅读 · 0 评论 -
[LEETCODE] 372. super pow
【LEETCODE】372.super powYour task is to calculate ab mod 1337 where a is a positive integer and b is an extremely large positive integer given in the form of an array.Example1:a = 2 b = [3]Result: 8原创 2016-07-23 20:41:01 · 383 阅读 · 0 评论 -
[LEETCODE] 268. Missing Number
[LEETCODE]268. Missing NumberGiven an array containing n distinct numbers taken from 0, 1, 2, …, n, find the one that is missing from the array.原创 2016-07-23 21:06:11 · 362 阅读 · 0 评论 -
[leetcode] 319.Bulb Switcher
[leetcode] 319.Bulb SwitcherThere are n bulbs that are initially off.原创 2016-07-23 23:27:53 · 1124 阅读 · 0 评论 -
[LEETCODE]52. N-Queens II
[LEETCODE]52. N-Queens IIFollow up for N-Queens problem.Now, instead outputting board configurations, return the total number of distinct solutions.原创 2016-07-24 09:58:55 · 1053 阅读 · 0 评论 -
[LEETCODE]318. Maximum Product of Word Lengths
[LEETCODE]318. Maximum Product of Word Lengths原创 2016-07-24 12:47:20 · 1023 阅读 · 0 评论 -
[LEETCODE] 287. Find the Duplicate Number
[LEETCODE] 287. Find the Duplicate NumberGiven an array nums containing n + 1 integers where each integer is between 1 and n (inclusive), prove that at least one duplicate number must exist. Assume tha原创 2016-07-24 13:08:54 · 1193 阅读 · 0 评论 -
[LeetCode] Counting Bits 计数位
LEETCODE counting bit原创 2016-07-14 11:13:16 · 372 阅读 · 0 评论 -
LeetCode 371 Sum of Two Intergers
leetcode 371 sum of two intergers原创 2016-07-14 11:32:42 · 414 阅读 · 0 评论 -
Leetcode 第 374 题(Guess Number Higher or Lower)
leetcode 374原创 2016-07-15 16:57:45 · 408 阅读 · 0 评论 -
leetcode Find K Pairs with Smallest Sums
leetcode 373find K pairs with Smallest Sums原创 2016-07-15 23:06:52 · 449 阅读 · 0 评论 -
leetcode amazon 面试题(三)
leetcode 21. merge two sorted lists大概的意思就是 给两个list, 然后把它们按照所有元素的 从小到大的顺序排序。这里分享一个比较简洁的写法:class Solution(object): def mergeTwoLists(self, l1, l2): dummy = cur = ListNode(0) while l...原创 2018-03-20 04:10:34 · 1242 阅读 · 0 评论