随笔分类 -  LeetCode

二叉树的前、中、后、层序遍历的递归实现
摘要:前中后序三种遍历方法对于左右结点的遍历顺序都是一样的(先左后右),唯一不同的就是根节点的出现位置。 1.前序:前序遍历指根结点在最前面输出,所以前序遍历的顺序是:中左右。 递归:class Solution: def preorderTraversal(self, root): ##前序遍历 """ 阅读全文

posted @ 2021-04-16 14:53 不要挡着我晒太阳 阅读(273) 评论(0) 推荐(0) 编辑

环形链表()
摘要:法一: class Solution: def hasCycle(self, head: ListNode) -> bool: a = set() while head: if head in a: return True a.add(head) head = head.next return Fa 阅读全文

posted @ 2020-08-19 16:22 不要挡着我晒太阳 阅读(96) 评论(0) 推荐(0) 编辑

合并两个有序链表(21)
摘要:# Definition for singly-linked list. # class ListNode: # def __init__(self, x): # self.val = x # self.next = None 法一: class Solution: def mergeTwoList 阅读全文

posted @ 2020-08-19 11:28 不要挡着我晒太阳 阅读(109) 评论(0) 推荐(0) 编辑

删除链表倒数第n个节点(19)
摘要:法一:# Definition for singly-linked list. # class ListNode: # def __init__(self, x): # self.val = x # self.next = None class Solution: def removeNthFrom 阅读全文

posted @ 2020-08-17 17:16 不要挡着我晒太阳 阅读(54) 评论(0) 推荐(0) 编辑

Z字形变换(6)
摘要:class Solution: def convert(self, s: str, numRows: int) -> str: if numRows < 2: return s res = ["" for _ in range(numRows)] i, flag = 0, -1 for c in s 阅读全文

posted @ 2020-08-13 11:21 不要挡着我晒太阳 阅读(95) 评论(0) 推荐(0) 编辑

三数之和(15)
摘要:class Solution(object): def threeSum(self, nums): """ :type nums: List[int] :rtype: List[List[int]] """ nums.sort() if not nums or len(nums)<3: return 阅读全文

posted @ 2020-08-11 17:32 不要挡着我晒太阳 阅读(72) 评论(0) 推荐(0) 编辑

两数之和(1)
摘要:法一: class Solution: def twoSum(self, nums: List[int], target: int) -> List[int]: ret = [] for i in range(len(nums)): for j in range(1,len(nums)-i): if 阅读全文

posted @ 2020-08-11 14:22 不要挡着我晒太阳 阅读(66) 评论(0) 推荐(0) 编辑

加一(66)
摘要:法一: class Solution: def plusOne(self, digits: List[int]) -> List[int]: length = len(digits) res = 0 for i in digits: if digits[-1]!=9: if length!=1: r 阅读全文

posted @ 2020-08-05 15:48 不要挡着我晒太阳 阅读(165) 评论(0) 推荐(0) 编辑

原地删除(27)
摘要:法一: class Solution: def removeElement(self, nums: List[int], val: int) -> int: for i in range(len(nums)-1, -1, -1): if(nums[i] == val): nums.pop(i) re 阅读全文

posted @ 2020-08-03 13:48 不要挡着我晒太阳 阅读(113) 评论(0) 推荐(0) 编辑

旋转数组(189)
摘要:法一: class Solution: def rotate(self, nums: List[int], k: int) -> None: """ Do not return anything, modify nums in-place instead. """ n = len(nums) k % 阅读全文

posted @ 2020-08-03 10:39 不要挡着我晒太阳 阅读(112) 评论(0) 推荐(0) 编辑

买卖股票的最佳时机 II(122)
摘要:法一:class Solution: def maxProfit(self, prices: List[int]) -> int: ret = 0 for i in range(len(prices)): if i+1<len(prices): if prices[i]<prices[i+1]: r 阅读全文

posted @ 2020-07-31 11:27 不要挡着我晒太阳 阅读(169) 评论(0) 推荐(0) 编辑

最长公共前缀(14)
摘要:法一:class Solution: def longestCommonPrefix(self, strs: List[str]) -> str: if not strs: return '' str_min = min(strs) str_max = max(strs) for i in rang 阅读全文

posted @ 2020-07-30 11:32 不要挡着我晒太阳 阅读(89) 评论(0) 推荐(0) 编辑

两个数组的交集II(350)
摘要:法一:def intersect(nums1, nums2): """ :type nums1: List[int] :type nums2: List[int] :rtype: List[int] """ ans = [] nums1.sort() nums2.sort() i = j = 0 w 阅读全文

posted @ 2020-07-29 14:22 不要挡着我晒太阳 阅读(130) 评论(0) 推荐(0) 编辑

SQL练习02
摘要:编写一个 SQL 查询,获取 Employee 表中第二高的薪水(Salary) 。 + + +| Id | Salary |+ + +| 1 | 100 || 2 | 200 || 3 | 300 |+ + +例如上述 Employee 表,SQL查询应该返回 200 作为第二高的薪水。如果不存在 阅读全文

posted @ 2019-11-25 20:50 不要挡着我晒太阳 阅读(109) 评论(0) 推荐(0) 编辑

SQL练习
摘要:表1: Person + + +| 列名 | 类型 |+ + +| PersonId | int || FirstName | varchar || LastName | varchar |+ + +PersonId 是上表主键表2: Address + + +| 列名 | 类型 |+ + +| A 阅读全文

posted @ 2019-11-25 18:57 不要挡着我晒太阳 阅读(79) 评论(0) 推荐(0) 编辑

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

导航

统计

点击右上角即可分享
微信分享提示