lkjhxx
lkjhxx
全部文章
分类
题解(54)
归档
标签
去牛客网
登录
/
注册
lkjhxx的博客
困难题唯唯诺诺,简单题重拳出击
全部文章
(共54篇)
刷题记录:二维数组中的查找
其实我想暴力的,但奈何时间复杂度不允许 后面考虑到矩阵有序,于是想试试将矩阵分为四分,遍历其中一个矩阵 但太麻烦也被我否决了 后面实在想不出来,求助评论区 具体思路是:从矩阵左下角出发,比 target 小则右移,比 target 大则上移 代码如下: class Solution: def...
Python3
2022-07-27
0
241
刷题记录:二分查找-I
温故而知新,可以为师矣 双指针法 代码如下: class Solution: def search(self , nums: List[int], target: int) -> int: low, high = 0, len(nums) - 1 whi...
Python3
2022-07-27
0
270
LeetCode每日一题:完全二叉树插入器
如何创建二叉树忘完了,直接看评论区 发现队列,想起一点 代码如下: class CBTInserter: def __init__(self, root: TreeNode): self.treeList = [] self.treeList.append(r...
Python3
2022-07-26
0
221
刷题记录:删除有序链表中重复的元素-II
首先考虑头结点重复,直接添加一个新结点 preHead 作为头结点 然后考虑重复,这里使用 temp 保存重复的值,通过对比重复的值来删除重复结点中的第一个 循环由删除有序链表中重复的元素-I修改而来 代码如下: class Solution: def deleteDuplicates(se...
Python3
2022-07-26
0
240
刷题记录:删除有序链表中重复的元素-I
代码如下: class Solution: def deleteDuplicates(self , head: ListNode) -> ListNode: p = head while p and p.next: if p.va...
Python3
2022-07-26
0
248
刷题记录:链表的奇偶重排
很快嗷,一遍过 代码如下: class Solution: def oddEvenList(self , head: ListNode) -> ListNode: if not head or not head.next: return head...
Python3
2022-07-26
0
199
刷题记录:判断一个链表是否为回文结构
快慢指针分两半,然后逆序后半链表,之后对比 代码如下: class Solution: def isPail(self , head: ListNode) -> bool: pre, slow, fast = head, head, head while...
Python3
2022-07-25
0
236
刷题记录:单链表的排序
我第一个想法是分治 但想到分治之后就不知道该咋做了 卡了许久,遂求助官解 得“排序”二字 于是想起了合并两个排序的链表 遂得代码,如下: class Solution: def sortInList(self , head: ListNode) -> ListNode: ...
Python3
2022-07-25
0
274
刷题记录:链表相加(二)
反转两列表,然后从头加到尾 代码如下: class Solution: def addInList(self , head1: ListNode, head2: ListNode) -> ListNode: p1 = self.reverseList(head1) ...
Python3
2022-07-25
0
272
LeetCode每日一题:公交站间的距离
就,顺时针路程加逆时针路程等于总路程,找最小即可 class Solution: def distanceBetweenBusStops(self, distance: List[int], start: int, destination: int) -> int: i...
Python3
2022-07-24
0
234
首页
上一页
1
2
3
4
5
6
下一页
末页