leetcode
文章平均质量分 54
qq184861643
这个作者很懒,什么都没留下…
展开
-
leetcode: Best Time to Buy and Sell Stock with Cooldown
文中所有图片中循环箭头上的wait都应该改为loop,意为经历一次循环。Question: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原创 2018-01-23 12:53:27 · 157 阅读 · 0 评论 -
leetcode: Linked List
QuestionGiven a linked list, determine if it has a cycle in it.Follow up:Can you solve it without using extra space?Solution# Definition for singly-linked list.# class ListNode(object):# de...原创 2018-10-27 22:45:31 · 95 阅读 · 0 评论 -
【转载】快速排序(三种算法实现和非递归实现)
原文地址python实现:import randoma = [4,1,7,6,9,2,2,3,5,7,8,9,3,1,2,3,4,5,8,0,3,5]b = [4,1,7,6,9,2,8,0,3,5]def twoPointerSort(nums,left,right): key = random.randint(left,right) nums[right],nums[...原创 2018-11-01 20:24:02 · 331 阅读 · 0 评论 -
Leetcode: Subarray Sum Equals K\\\Binary Subarrays With Sum
ProblemGiven an array of integers and an integer k, you need to find the total number of continuous subarrays whose sum equals to k.Example 1:Input: nums = [1,1,1], k = 2Output: 2Note:The le...原创 2018-11-12 21:32:06 · 106 阅读 · 0 评论 -
leecode: Delete Operation for Two Strings
https://leetcode.com/problems/delete-operation-for-two-strings/转载 2018-11-23 22:56:51 · 76 阅读 · 0 评论 -
leetcode: Ambiguous Coordinates
https://leetcode.com/problems/ambiguous-coordinates/解题思路先把string分成左右两部分,每部分至少有一个值,中间放入逗号空格。再对每部分放小数点,放小数点时把不被允许的情况排除在外。...转载 2018-11-28 21:19:08 · 133 阅读 · 0 评论 -
leetcode: Word Subsets
https://leetcode.com/problems/word-subsets/解题思路:先将B中的所有单词b组合成一个极大单词bmax再解题,bmax中每个字母的出现次数为所有b中字母出现次数的最大值而不是相加。例如,B=[‘wrr’,‘ao’, ‘ro’],则bmax=‘arrow’。B中‘r’在单个b中出现次数的极大值为2,总次数为3,‘o’出现的极大值为1,总次数为2,所以bma...转载 2018-11-26 09:35:56 · 107 阅读 · 0 评论 -
leetcode: Reorganize String
https://leetcode.com/problems/reorganize-string/解题思路首先对S里每个字母出现的次数进行统计,如果存在某个字母出现的次数大于len(S)//2+1len(S)//2+1len(S)//2+1,则直接返回""。若没有则:1.循环返回剩下的字母中,出现次数最多和次多的字母,知道全部返回了为止。2.new一个字母按照出现次数从大到小排序的Strin...转载 2018-11-30 21:51:06 · 146 阅读 · 0 评论 -
leetcode: Subarray Sums Divisible by K
ProblemGiven an array A of integers, return the number of (contiguous, non-empty) subarrays that have a sum divisible by K.Example 1:Input: A = [4,5,0,-2,-3,1], K = 5Output: 7Explanation: There a...原创 2019-02-22 22:33:19 · 127 阅读 · 0 评论 -
leetcode: 二叉树的三种非递归遍历
class TreeNode: def __init__(self,val): super(TreeNode).__init__() self.val = val self.left = None self.right = None self.isPop = Falsedef createTree(valL...原创 2018-10-18 22:37:18 · 367 阅读 · 0 评论 -
leetcode: 2 Keys Keyboard
QuestionInitially on a notepad only one character ‘A’ is present. You can perform two operations on this notepad for each step:Copy All: You can copy all the characters present on the notepad (parti...原创 2018-10-17 23:49:02 · 86 阅读 · 0 评论 -
leetcode:Smallest Subtree with all the Deepest Nodes
ProblemGiven a binary tree rooted at root, the depth of each node is the shortest distance to the root. A node is deepest if it has the largest depth possible among any node in the entire tree. Th...原创 2018-07-21 00:22:28 · 229 阅读 · 0 评论 -
leetcode: Best Time to Buy and Sell Stock III
QuestionSay 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 complete at most two transactions.Note: Yo原创 2018-01-24 15:49:35 · 101 阅读 · 0 评论 -
leetcode: Find the Duplicate Number
QuestionGiven 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 that there is only one duplicate ...原创 2018-02-09 16:03:06 · 155 阅读 · 0 评论 -
leetcode: Max Chunks To Make Sorted II
QuestionGiven an array arr of integers (not necessarily distinct), we split the array into some number of “chunks” (partitions), and individually sort each chunk. After concatenating them, the resu原创 2018-01-29 18:51:25 · 196 阅读 · 0 评论 -
leetcode: Maximum Length of Repeated Subarray
QuestionGiven two integer arrays A and B, return the maximum length of an subarray that appears in both arrays.Example 1 Input: A: [1,2,3,2,1] B: [3,2,1,4,7] Output: 3 Explanation:...原创 2018-02-12 22:55:01 · 185 阅读 · 0 评论 -
leetcode: My Calender I
QuestionImplement a MyCalendar class to store your events. A new event can be added if adding the event will not cause a double booking.Your class will have the method, book(intstart,intend)book(i...原创 2018-02-07 22:21:15 · 194 阅读 · 0 评论 -
leetcode: Convert BST to Greater Tree
ProblemGiven a Binary Search Tree (BST), convert it to a Greater Tree such that every key of the original BST is changed to the original key plus sum of all keys greater than the original key in BST...原创 2018-03-14 22:30:21 · 150 阅读 · 0 评论 -
leetcode:4Sum II
ProblemGiven four lists A, B, C, D of integer values, compute how many tuples (i, j, k, l) there are such that A[i] + B[j] + C[k] + D[l] is zero.To make problem a bit easier, all A, B, C, D have s...原创 2018-02-22 09:56:26 · 161 阅读 · 0 评论 -
leetcode:Balanced Binary Tree
ProblemGiven a binary tree, determine if it is height-balanced.For this problem, a height-balanced binary tree is defined as:a binary tree in which the depth of the two subtrees of every node ne...原创 2018-04-03 11:17:12 · 102 阅读 · 0 评论 -
leetcode: Maximum Width Ramp
ProblemGiven an array A of integers, a ramp is a tuple (i, j) for which i < j and A[i] <= A[j]. The width of such a ramp is j - i.Find the maximum width of a ramp in A. If one doesn’t exist,...原创 2019-02-24 17:44:52 · 115 阅读 · 0 评论