![](https://img-blog.csdnimg.cn/20201014180756925.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
leetcode
文章平均质量分 75
千追万追
目前是学生。熟悉Python、Java、HTML/CSS/JavaScript。关注Leetcode和Web全栈。
展开
-
leetcode 23. Merge k Sorted Lists的思路与python实现 (Priority Queue)
Mergeksorted linked lists and return it as one sorted list. Analyze and describe its complexity.Example:Input:[ 1->4->5, 1->3->4, 2->6]Output: 1->1->2->3->4-...原创 2019-12-06 13:13:03 · 330 阅读 · 0 评论 -
leetcode 4. Median of Two Sorted Arrays的思路与python实现
思路基本只能靠背。边缘条件太恶心了...代码class Solution: def findMedianSortedArrays(self, nums1: List[int], nums2: List[int]) -> float: m, n = len(nums1), len(nums2) if m > n: # 上面的要小一点...原创 2019-11-04 17:17:38 · 201 阅读 · 0 评论 -
leetcode 16. 3Sum Closest的思路与python实现
我的leetcode系列博文一般没什么参考价值,思路一般懒得叙述完整。代码可以看看,不过leetcode的discussion里有更好的。纯属随便记录。思路这题跟3SUM的做法差不多。记得先把数组sort了。在比较当前solution和存储的solution哪个好的时候,记得使用abs算绝对值。要思考的是3SUM里使用的left, right双指针寻找exactly的solut...原创 2019-11-01 13:31:44 · 99 阅读 · 0 评论 -
leetcode 2. Add Two Numbers的思路与python实现
You are given twonon-emptylinked lists representing two non-negative integers. The digits are stored inreverse orderand each of their nodes contain a single digit. Add the two numbers and return i...原创 2019-10-31 15:33:18 · 103 阅读 · 0 评论 -
leetcode 133. Clone Graph的思路与python实现
Givena reference of a node in aconnectedundirected graph, return adeep copy(clone) of the graph. Each node in the graph contains a val (int) and a list (List[Node]) of its neighbors.Example:...原创 2019-08-13 21:02:01 · 162 阅读 · 0 评论 -
Amazon | Online Assessment 2019 | Roll Dice的思路与python实现
题目链接:https://leetcode.com/discuss/interview-question/331158/Amazon-or-Online-Assessment-2019-or-Roll-DiceA six-sided die is a small cube with a different number of pips on each face (side), ranging ...原创 2019-08-07 15:29:45 · 1818 阅读 · 0 评论 -
leetcode 120. Triangle 的思路与python实现
Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjacent numbers on the row below.For example, given the following triangle[ [2], [3,4], [6,5...原创 2019-08-14 20:45:15 · 194 阅读 · 0 评论 -
leetcode 146. LRU Cache的思路与python实现
Design and implement a data structure forLeast Recently Used (LRU) cache. It should support the following operations:getandput.get(key)- Get the value (will always be positive) of the key if th...原创 2019-08-10 18:04:03 · 163 阅读 · 0 评论 -
leetcode 76. Minimum Window Substring的思路与python实现
Given a string S and a string T, find the minimum window in S which will contain all the characters in T in complexity O(n).Example:Input: S = "ADOBECODEBANC", T = "ABC"Output: "BANC"Note:I...原创 2019-08-22 03:21:47 · 277 阅读 · 0 评论 -
leetcode 140. Word Break II的思路与python实现
Given anon-emptystringsand a dictionarywordDictcontaining a list ofnon-emptywords, add spaces insto construct a sentence where each word is a valid dictionary word.Return all such possible s...原创 2019-08-22 15:05:34 · 269 阅读 · 0 评论 -
lintcode 629. Minimum Spanning Tree 的思路与python实现
Given a list of Connections, which is the Connection class (the city name at both ends of the edge and a cost between them), find edges that can connect all the cities and spend the least amount.Retu...原创 2019-08-02 12:24:52 · 470 阅读 · 0 评论 -
leetcode 25. Reverse Nodes in k-Group的思路与python实现
Given a linked list, reverse the nodes of a linked listkat a time and return its modified list.kis a positive integer and is less than or equal to the length of the linked list. If the number of ...原创 2019-08-02 12:05:23 · 183 阅读 · 0 评论 -
Leetcode 《3. 无重复字符的最长子串》 之Python实现
给定一个字符串,请你找出其中不含有重复字符的 最长子串 的长度。示例 1:输入: "abcabcbb"输出: 3 解释: 因为无重复字符的最长子串是"abc",所以其长度为 3。示例 2:输入: "bbbbb"输出: 1解释: 因为无重复字符的最长子串是"b",所以其长度为 1。示例 3:输入: "pwwkew"输出: 3解释: 因为无重复字符的最长子串...原创 2018-12-22 00:57:25 · 106 阅读 · 0 评论 -
leetcode 155. Min Stack 的思路与python实现
Design a stack that supports push, pop, top, and retrieving the minimum element in constant time.push(x) – Push element x onto stack.pop() – Removes the element on top of the stack.top() – Get the...原创 2019-07-02 17:12:52 · 122 阅读 · 0 评论 -
leetcode 670. Maximum Swap 的思路与python实现
Given a non-negative integer, you could swap two digitsat mostonce to get the maximum valued number. Return the maximum valued number you could get.Input: 2736Output: 7236Explanation: Swap the ...原创 2019-07-05 17:54:19 · 466 阅读 · 0 评论 -
leetcode 819. Most Common Word 的思路与python实现
Given a paragraphand a list of banned words, return the most frequent word that is not in the list of banned words. It is guaranteed there is at least one word that isn't banned, and that the answer...原创 2019-07-31 17:38:21 · 194 阅读 · 0 评论 -
leetcode 937. Reorder Log Files 的思路与python实现
You have an array oflogs. Each log is a space delimited string of words.For each log, the first word in each log is an alphanumericidentifier. Then, either:Each word after the identifier will ...原创 2019-07-31 18:27:32 · 131 阅读 · 0 评论 -
leetcode 124. Binary Tree Maximum Path Sum的思路与python实现
Given anon-emptybinary tree, find the maximum path sum.For this problem, a path is defined as any sequence of nodes from some starting node to any node in the tree along the parent-child connectio...原创 2019-08-01 01:59:07 · 180 阅读 · 0 评论 -
leetcode 116 & 117. Populating Next Right Pointers in Each Node 的思路与python实现
You are given aperfect binary treewhereall leaves are on the same level, and every parent has two children. The binary tree has the following definition:struct Node { int val; Node *left; ...原创 2019-07-27 16:34:19 · 106 阅读 · 0 评论 -
leetcode 92. Reverse Linked List II 的思路与python实现
Reverse a linked list from positionmton. Do it in one-pass.Note:1 ≤m≤n≤ length of list.Example:Input: 1->2->3->4->5->NULL, m = 2, n = 4Output: 1->4->3->2->5-...原创 2019-07-27 22:41:15 · 157 阅读 · 0 评论 -
leetcode 763. Partition Labels 的思路与python实现
A stringSof lowercase letters is given. We want to partition this string into as many parts as possible so that each letter appears in at most one part, and return a list of integers representing th...原创 2019-07-28 01:09:12 · 202 阅读 · 0 评论 -
Leetcode 《2. 两数相加》 之JS实现
准备面试,临时抱佛脚地开始刷leetcode,顺便练习一下javascript,决定把过程放博客记录一下,主要是总结比较个人的问题,大家可以不看。题目《2. 两数相加》给出两个 非空 的链表用来表示两个非负的整数。其中,它们各自的位数是按照 逆序 的方式存储的,并且它们的每个节点只能存储 一位 数字。如果,我们将这两个数相加起来,则会返回一个新的链表来表示它们的和。您可以假设除了...原创 2018-12-01 02:28:39 · 1454 阅读 · 1 评论