01 2021 档案
Datawhale编程实践(LeetCode 腾讯精选练习50)Task17
摘要:1.反转字符串https://leetcode-cn.com/problems/reverse-string/ 一开始没想到,看了解答才恍然大悟原来这么简单 双指针法 1 class Solution: 2 def reverseString(self, s: List[str]) -> None: 阅读全文
posted @ 2021-01-27 21:34 zmbreathing 阅读(102) 评论(0) 推荐(0)
Datawhale编程实践(LeetCode 腾讯精选练习50)Task16
摘要:1.删除链表中的节点https://leetcode-cn.com/problems/delete-node-in-a-linked-list/ 一开始没看清题目中传入的参数为“要被删除的节点”,找了半天链表在哪 1 class ListNode: 2 def __init__(self, x): 阅读全文
posted @ 2021-01-27 21:24 zmbreathing 阅读(81) 评论(0) 推荐(0)
Datawhale编程实践(LeetCode 腾讯精选练习50)Task15
摘要:1.2的幂https://leetcode-cn.com/problems/power-of-two/ 我的想法是不停地除以2,直到不能整除,最终为1则返回True,否则返回False 时间复杂度48% 1 class Solution: 2 def isPowerOfTwo(self, n: in 阅读全文
posted @ 2021-01-27 16:01 zmbreathing 阅读(108) 评论(0) 推荐(0)
Datawhale编程实践(LeetCode 腾讯精选练习50)Task14
摘要:1.数组中的第k个最大元素https://leetcode-cn.com/problems/kth-largest-element-in-an-array/ 看到这题只想到排序之后取第k个元素,那就是一个最基本的排序问题了 看了解答之后理解了“快速选择”思想,即在快排的过程中只递归目标方向。 1 i 阅读全文
posted @ 2021-01-26 19:27 zmbreathing 阅读(146) 评论(0) 推荐(0)
Datawhale编程实践(LeetCode 腾讯精选练习50)Task13
摘要:1.相交链表https://leetcode-cn.com/problems/intersection-of-two-linked-lists/ 看到这个题目没有理解示例1到底是什么意思,为什么都有1但相交的起始节点不是1那个点 后来知道了是要节点本身相等(不仅包括值还包括地址)。 看到官方的双指针 阅读全文
posted @ 2021-01-25 20:26 zmbreathing 阅读(92) 评论(0) 推荐(0)
Datawhale编程实践(LeetCode 腾讯精选练习50)Task12
摘要:1.LRU缓存机制https://leetcode-cn.com/problems/lru-cache/ 拿到题目先想的是用字典,删除元素就想找是否有可以顺序删除字典元素的方法,但是好像没有 看了官方答案感觉有点高深,哈希表+双向链表 1 class DLinkedNode: 2 def __ini 阅读全文
posted @ 2021-01-23 10:03 zmbreathing 阅读(118) 评论(0) 推荐(0)
Datawhale编程实践(LeetCode 腾讯精选练习50)Task11
摘要:1.只出现一次的数字https://leetcode-cn.com/problems/single-number/ 看到“你的算法应该具有线性时间复杂度。 你可以不使用额外空间来实现吗?”我也想了很久,想不出答案,最终看了解答 位运算和异或运算确实之前没有接触过,这里让我大开眼界 1 class S 阅读全文
posted @ 2021-01-22 20:41 zmbreathing 阅读(64) 评论(0) 推荐(0)
Datawhale编程实践(LeetCode 腾讯精选练习50)Task10
摘要:1.买卖股票的最佳时机https://leetcode-cn.com/problems/best-time-to-buy-and-sell-stock/ 拿到这题首先想到最暴力的方法,遍历 1 class Solution: 2 def maxProfit(self, prices: List[in 阅读全文
posted @ 2021-01-21 17:35 zmbreathing 阅读(131) 评论(0) 推荐(0)
Datawhale编程实践(LeetCode 腾讯精选练习50)Task9
摘要:1.合并两个有序数组https://leetcode-cn.com/problems/merge-sorted-array/ 一开始看到这题在想这个有序数组是升序还是降序是不是需要判断一下 在https://www.cnblogs.com/easonbook/p/12876402.html看到了Na 阅读全文
posted @ 2021-01-20 20:17 zmbreathing 阅读(122) 评论(0) 推荐(0)
Datawhale编程实践(LeetCode 腾讯精选练习50)Task8
摘要:1.不同路径https://leetcode-cn.com/problems/unique-paths/ 看到这题,我第一想到的也是组合数学。就直接计算一下组合数就行了 1 class Solution: 2 def uniquePaths(self, m: int, n: int) -> int: 阅读全文
posted @ 2021-01-19 10:22 zmbreathing 阅读(112) 评论(0) 推荐(0)
Datawhale编程实践(LeetCode 腾讯精选练习50)Task7
摘要:1.螺旋矩阵https://leetcode-cn.com/problems/spiral-matrix/ 看到这题我第一时间想到的也是用辅助矩阵visited,时间复杂度和空间复杂度都是O(mn) 1 class Solution: 2 def spiralOrder(self, matrix: 阅读全文
posted @ 2021-01-18 23:35 zmbreathing 阅读(141) 评论(0) 推荐(0)
Datawhale编程实践(LeetCode 腾讯精选练习50)Task6
摘要:1.字符串相乘https://leetcode-cn.com/problems/multiply-strings/ 学到了for i in range(a, b, c)的用法,其中c为步长 复习了python 字符串的各种操作 对这题的要求和答案不是很理解,要求不能直接将输入转换为整数来处理,但是答 阅读全文
posted @ 2021-01-18 01:09 zmbreathing 阅读(107) 评论(0) 推荐(0)
Datawhale编程实践(LeetCode 腾讯精选练习50)Task5
摘要:1.合并K个升序链表https://leetcode-cn.com/problems/merge-k-sorted-lists/ 这题是leetcode的一个困难题 这里对将两个升序链表进行合并进行了复习,C++代码如下 1 ListNode* mergeTwoLists(ListNode *a, 阅读全文
posted @ 2021-01-16 22:30 zmbreathing 阅读(105) 评论(0) 推荐(0)
Datawhale编程实践(LeetCode 腾讯精选练习50)Task4
摘要:1.最接近的三数之和https://leetcode-cn.com/problems/3sum-closest/submissions/ 这一题的思路也是双指针降低遍历次数,暴力法时间复杂度为O(n^3),双指针将时间复杂度降为O(n^2),不过此题采用双指针需要进行一个排序 1 class Sol 阅读全文
posted @ 2021-01-15 17:11 zmbreathing 阅读(166) 评论(0) 推荐(0)
Datawhale编程实践(LeetCode 腾讯精选练习50)Task3
摘要:1.盛最多水的容器https://leetcode-cn.com/problems/container-with-most-water/ 看了一会这道题只能想到暴力法,显然暴力法时间复杂度O(n^2),效率很低 看了官方解答,答案关键点为双指针https://leetcode-cn.com/prob 阅读全文
posted @ 2021-01-14 02:01 zmbreathing 阅读(138) 评论(0) 推荐(0)
Datawhale编程实践(LeetCode 腾讯精选练习50)Task2
摘要:1.整数反转 这题让我学到了整数溢出的知识,查阅了资料https://blog.csdn.net/weixin_45722061/article/details/102579358,其中提到 1 Python 3 中整数的上限是多少?Python 2 呢? 2 Numpy 中整数的上限是多少?出现整 阅读全文
posted @ 2021-01-13 01:22 zmbreathing 阅读(131) 评论(0) 推荐(0)
Datawhale编程实践(LeetCode 腾讯精选练习50)Task1
摘要:1.两数相加 https://leetcode-cn.com/problems/add-two-numbers/ 自己的代码能力果然很差,写出来直接超时。 1 # Definition for singly-linked list. 2 3 class ListNode(object): 4 def 阅读全文
posted @ 2021-01-12 01:43 zmbreathing 阅读(129) 评论(0) 推荐(0)