- 博客(17)
- 收藏
- 关注
原创 2021-01-30
344.反转字符串 class Solution: def reverseString(self, s: List[str]) -> None: """ Do not return anything, modify s in-place instead. """ i, j = 0, len(s) - 1 while i<j: s[i],s[j]=s[j],s[i] i+=1 j-=1 return
2021-01-30 00:08:19
58
原创 2021-01-28
237.删除链表中的节点 # Definition for singly-linked list. # class ListNode: # def __init__(self, x): # self.val = x # self.next = None class Solution: def deleteNode(self, node): node.val=node.next.val node.next=node.next.n
2021-01-28 16:32:24
58
原创 2021-01-28
231.2的幂 if(n<=0):return false else if((n&n-1)==0):return true else return false 235.二叉搜索树的最近公共祖先 class Solution(object): def lowestCommonAncestor(self, root, p, q): """ :type root: TreeNode :type p: TreeNode :typ
2021-01-28 01:13:36
74
原创 2021-01-27
215.数组中的第K个最大元素 class Solution: def findKthLargest(self, nums: List[int], k: int) -> int: if len(nums) == 1: return nums[0] mid = int(len(nums) // 2) left, right, mids = [], [], [] for i in range(len(nums)):
2021-01-27 00:51:05
56
原创 2021-01-26
160.相交链表 # Definition for singly-linked list. # class ListNode: # def __init__(self, x): # self.val = x # self.next = None class Solution: def getIntersectionNode(self, headA: ListNode, headB: ListNode) -> ListNode: cur1
2021-01-26 00:37:18
52
原创 2021-01-24
146.LRU缓存机制 class LRUCache: def __init__(self, capacity: int): self.capacity = capacity self.cache = {} def get(self, key: int) -> int: # 搜索不到返回-1 if key not in self.cache: return -1 # 取出缓存中的k
2021-01-24 00:53:20
68
2
原创 2021-01-21
136.只出现一次的数字 class Solution: def singleNumber(self, nums): """ :type nums: List[int] :rtype: int """ a = 0 for num in nums: a = a ^ num return a 141.环形链表I class Solution: def hasC
2021-01-21 15:53:15
60
原创 2021-01-21
买卖股票的最佳时机 class Solution: def maxProfit(self, prices): """ :type prices: List[int] :rtype: int """ min_p, max_p = 999999, 0 for i in range(len(prices)): min_p = min(min_p, prices[i]) .
2021-01-21 15:35:00
90
原创 2021-01-20
88.合并两个有序链表 class Solution: def merge(self, nums1: List[int], m: int, nums2: List[int], n: int) -> None: """ Do not return anything, modify nums1 in-place instead. """ nums1[m:m+n] = nums2 # 将nums2合并到nums1中
2021-01-20 19:36:06
66
原创 2021-01-20
62.不同路径 class Solution(object): def uniquePaths(self, m, n): dp = [[0 for _ in range(n)] for _ in range(m)] dp[0][0] = 0 for i in range(m): dp[i][0] = 1 for j in range(n): dp[0][j] = 1
2021-01-20 00:25:31
72
原创 2021-01-18
54.螺旋矩阵 class solution: def spiralOrder(self, matrix: List[List[int]]) -> List[int]: if not matrix: return [] res = matrix[0] matrix = [list(x) for x in zip(*matrix[1:])][::-1] res += self.spiralOrder(matrix)
2021-01-18 22:24:19
52
原创 2021-01-18
字符串相乘 def multiply(self, num1, num2): res = 0 for i in range(1,len(num1)+1): for j in range(1, len(num2)+1): res += int(num1[-i]) * int(num2[-j]) *10**(i+j-2) return str(res) 46… 全排列 class Solution: .
2021-01-18 01:09:12
71
原创 2021-01-17
23.合并k个升序链表 ```python class Solution: def mergeKLists(self, lists: List[ListNode]) -> ListNode: n = len(lists) def merge(left, right): if left > right: return if left == right:
2021-01-17 00:35:46
69
原创 2021-01-15 leetcode
16.最接近的三数之和 class Solution: def threeSumClosest(self, nums: List[int], target: int) -> int: nums, r, end = sorted(nums), float('inf'), len(nums) - 1 for c in range(len(nums) - 2): i, j = max(c + 1, bisect.bisect_left(nums
2021-01-15 18:24:13
71
原创 03-2021-01-13 leetcode
11.盛水最多容器 class Solution: def maxArea(self, height: List[int]): -> int:\ left = 0 right = len(height) - 1 while left<right: area = min(height[left], height[right]) * (right - left) ans = max(ans, ar
2021-01-13 20:16:30
63
原创 02-2021-01-11leetcode
7.整数翻转 class Solution: def __reversed__(self, x:int)->int: int_max = 2**31-1 int_min = -(2**31) rev = 0 while x: pop = x%10 if x>0 else x%-10 x = x//10 if x>0 else int(x/10) i
2021-01-13 00:57:12
75
原创 01.2020-01-11 leetcode
2.两数相加 ```python # Definition for singly-linked list. # class ListNode: # def __init__(self, x): # self.val = x # self.next = None class Solution: def addTwoNumbers(self, l1: ListNode, l2: ListNode) -> ListNode: # 创建一个结点
2021-01-12 00:56:06
77
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人