
LeetCode
文章平均质量分 69
勿问情殇
做事认真,效率高,学习能力强,适应能力强。
外表女汉子,内心缺乏安全感,一名普普通通的程序媛。
展开
-
9. 回文数
题目描述请点击查看LeetCode 题目描述Python3 代码解答如下:class Solution: def isPalindrome(self, x): """ :type x: int :rtype: bool """ if x < 0: return False...原创 2018-12-26 14:04:14 · 162 阅读 · 0 评论 -
16. 最接近的三数之和
题目描述请点击查看LeetCode 题目描述Python3 代码解答如下:import sysclass Solution: def threeSumClosest(self, nums, target): """ :type nums: List[int] :type target: int :rtype: int...原创 2019-01-25 16:12:53 · 159 阅读 · 0 评论 -
17. 电话号码的字母组合
题目描述请点击查看LeetCode 题目描述Python3 代码解答如下:import reclass Solution: def cc(self,a,b): if len(a) < len(b): d = a a = b b = d c = [] if ...原创 2019-01-25 16:14:46 · 166 阅读 · 0 评论 -
18. 四数之和
题目描述请点击查看LeetCode 题目描述Python3 代码解答如下:class Solution: def fourSum(self, nums, target): """ :type nums: List[int] :type target: int :rtype: List[List[int]] ...原创 2019-01-25 16:16:06 · 151 阅读 · 0 评论 -
19. 删除链表的倒数第N个节点
题目描述请点击查看LeetCode 题目描述Python3 代码解答如下:# Definition for singly-linked list.# class ListNode:# def __init__(self, x):# self.val = x# self.next = Noneclass Solution: def ...原创 2019-01-25 16:17:36 · 144 阅读 · 0 评论 -
20. 有效的括号
题目描述请点击查看LeetCode 题目描述Python3 代码解答如下:class Solution: def isValid(self, s): """ :type s: str :rtype: bool """ """ 有效的字符串的: (){}[] 、 ({[]}) ...原创 2019-01-25 16:19:16 · 165 阅读 · 0 评论 -
21. 合并两个有序链表
题目描述请点击查看LeetCode 题目描述Python3 代码解答如下:# Definition for singly-linked list.# class ListNode:# def __init__(self, x):# self.val = x# self.next = Noneimport functoolsclass So...原创 2019-01-27 13:02:59 · 130 阅读 · 0 评论 -
23. 合并K个排序链表
题目描述请点击查看LeetCode 题目描述Python3 代码解答如下:# Definition for singly-linked list.# class ListNode:# def __init__(self, x):# self.val = x# self.next = Noneimport functoolsclass S...原创 2019-01-27 13:03:30 · 134 阅读 · 0 评论 -
24. 两两交换链表中的节点
题目描述请点击查看LeetCode 题目描述Python3 代码解答如下:# Definition for singly-linked list.# class ListNode:# def __init__(self, x):# self.val = x# self.next = Noneclass Solution: def ...原创 2019-01-27 13:03:39 · 177 阅读 · 0 评论 -
25. k个一组翻转链表
题目描述请点击查看LeetCode 题目描述Python3 代码解答如下:# Definition for singly-linked list.# class ListNode:# def __init__(self, x):# self.val = x# self.next = Noneclass Solution: def ...原创 2019-01-27 13:03:48 · 152 阅读 · 0 评论 -
26. 删除排序数组中的重复项
题目描述请点击查看LeetCode 题目描述Python3 代码解答如下:class Solution: def removeDuplicates(self, nums): """ :type nums: List[int] :rtype: int """ i = 0 for j in ..原创 2019-01-27 13:03:55 · 136 阅读 · 0 评论 -
27. 移除元素
题目描述请点击查看LeetCode 题目描述Python3 代码解答如下:class Solution: def removeElement(self, nums, val): """ :type nums: List[int] :type val: int :rtype: int """ ..原创 2019-01-27 13:04:05 · 160 阅读 · 0 评论 -
28. 实现strStr()
题目描述请点击查看LeetCode 题目描述Python3 代码解答如下:class Solution: def strStr(self, haystack, needle): """ :type haystack: str :type needle: str :rtype: int """ ..原创 2019-01-27 13:04:17 · 187 阅读 · 0 评论 -
15. 三数之和
题目描述请点击查看LeetCode 题目描述Python3 代码解答如下:class Solution: def threeSum(self, nums): """ :type nums: List[int] :rtype: List[List[int]] """ """ 思路:先将数组...原创 2019-01-25 16:09:44 · 159 阅读 · 0 评论 -
14. 最长公共前缀
题目描述请点击查看LeetCode 题目描述Python3 代码解答如下:class Solution: def longestCommonPrefix(self, strs): """ :type strs: List[str] :rtype: str """ """ 思路: 假定第一...原创 2019-01-25 16:07:42 · 171 阅读 · 0 评论 -
10. 正则表达式匹配
题目描述请点击查看LeetCode 题目描述Python3 代码解答如下:import reclass Solution: def isMatch(self, s, p): """ :type s: str :type p: str :rtype: bool """ a = re.fi...原创 2018-12-26 14:07:19 · 134 阅读 · 0 评论 -
LeetCode题库解答
此篇博客用于记录自己在 LeetCode 网站中所做过的习题,便于日后忘记了进行查阅。前期全部采用 Python3的语法来解答,后续时间充裕的话,希望自己可以试着用 JavaScript、C++/C 来解答。11. 盛最多水的容器题目描述请点击查看LeetCode 题目描述1. Python3 代码解答如下:class Solution: def maxArea(self,...原创 2018-12-26 14:21:43 · 869 阅读 · 0 评论 -
3. 无重复字符的最长子串
题目描述请点击查看LeetCode 题目描述Python3 代码解答如下:class Solution: def lengthOfLongestSubstring(self, s): """ :type s: str :rtype: int """ if s == "": ret...原创 2018-12-21 10:33:11 · 132 阅读 · 0 评论 -
2. 两个非空链表数值相加
题目描述请点击查看LeetCode 题目描述Python3 代码解答如下:# Definition for singly-linked list.# class ListNode:# def __init__(self, x):# self.val = x# self.next = Noneclass Solution: def ...原创 2018-12-21 11:37:50 · 319 阅读 · 0 评论 -
1. 两数之和 (等于目标值的下标)
题目描述请点击查看LeetCode 题目描述Python3 代码解答如下:class Solution: def twoSum(self, nums, target): """ :type nums: List[int] :type target: int :rtype: List[int] """ ...原创 2018-12-21 14:12:03 · 382 阅读 · 0 评论 -
4. 寻找两个有序数组的中位数
题目描述请点击查看LeetCode 题目描述代码解答如下:class Solution: def findMedianSortedArrays(self, nums1, nums2): &quot;&quot;&quot; :type nums1: List[int] :type nums2: List[int] :rtype: float ...原创 2018-12-11 18:24:52 · 244 阅读 · 0 评论 -
121. 买卖股票的最佳时机
题目描述请点击查看LeetCode 题目描述Python3 代码解答如下:class Solution: def maxProfit(self, prices): """ :type prices: List[int] :rtype: int """ if len(prices) == 0: ...原创 2018-12-12 10:07:48 · 131 阅读 · 0 评论 -
8. 字符串转换整数 (atoi)
题目描述请点击查看LeetCode 题目描述Python3 代码解答如下:import reclass Solution: def myAtoi(self, str): """ :type str: str :rtype: int """ s = str.strip() #去掉首尾空字符..原创 2018-12-25 18:05:13 · 329 阅读 · 0 评论 -
7. 整数反转
题目描述请点击查看LeetCode 题目描述Python3 代码解答如下:class Solution: def reverse(self, x): """ :type x: int :rtype: int """ a = x if a<0: a = -a...原创 2018-12-25 18:06:19 · 122 阅读 · 0 评论 -
11. 盛最多水的容器
题目描述请点击查看LeetCode 题目描述Python3 代码解答如下:class Solution: def maxArea(self, height): """ :type height: List[int] :rtype: int """ """ Python 抛弃暴力循环法,会...原创 2019-01-25 16:00:24 · 139 阅读 · 0 评论 -
12. 整数转罗马数字
题目描述请点击查看LeetCode 题目描述Python3 代码解答如下:class Solution: def intToRoman(self, num): """ :type num: int :rtype: str """ """ 思路:提取数字的各个位数,并加以判断,需要注意的是...原创 2019-01-25 16:03:42 · 159 阅读 · 0 评论 -
13. 罗马数字转整数
题目描述请点击查看LeetCode 题目描述Python3 代码解答如下:class Solution: def romanToInt(self, s): """ :type s: str :rtype: int """ """ 思路:罗马数字的字符对应的数值,基本上都是前一个比后一个大...原创 2019-01-25 16:05:31 · 241 阅读 · 0 评论 -
29. 两数相除
题目描述请点击查看LeetCode 题目描述Python3 代码解答如下:class Solution: def divide(self, dividend, divisor): """ :type dividend: int :type divisor: int :rtype: int """ ..原创 2019-01-27 13:04:24 · 220 阅读 · 0 评论