├── .gitignore ├── README.md └── code ├── 1. 两数之和.py ├── 100. 相同的树.py ├── 101. 对称二叉树.py ├── 1013. 将数组分成和相等的三个部分.py ├── 104. 二叉树的最大深度.py ├── 108. 将有序数组转换为二叉搜索树.py ├── 1089. 复写零.py ├── 110. 平衡二叉树.py ├── 1103. 分糖果 II.py ├── 1108. IP 地址无效化.py ├── 111. 二叉树的最小深度.py ├── 1114. 按序打印.py ├── 112. 路径总和.py ├── 1160. 拼写单词.py ├── 118. 杨辉三角.py ├── 119. 杨辉三角 II.py ├── 121. 买卖股票的最佳时机.py ├── 122. 买卖股票的最佳时机 II.py ├── 125. 验证回文串.py ├── 1266. 访问所有点的最小时间.py ├── 1281. 整数的各位积和之差.py ├── 1290. 二进制链表转整数.py ├── 1295. 统计位数为偶数的数字.py ├── 13. 罗马数字转整数.py ├── 1313. 解压缩编码列表.py ├── 1342. 将数字变成 0 的操作次数.py ├── 136. 只出现一次的数字.py ├── 1365. 有多少小于当前数字的数字.py ├── 138. 复制带随机指针的链表.py ├── 1389. 按既定顺序创建目标数组.py ├── 14. 最长公共前缀.py ├── 141. 环形链表.py ├── 1431. 拥有最多糖果的孩子.py ├── 1450. 在既定时间做作业的学生人数.py ├── 1470. 重新排列数组.py ├── 1480. 一维数组的动态和.py ├── 1486. 数组异或操作.py ├── 15. 三数之和.py ├── 150. 逆波兰表达式求值.py ├── 1512. 好数对的数目.py ├── 155. 最小栈.py ├── 1572. 矩阵对角线元素的和.py ├── 1588. 所有奇数长度子数组的和.py ├── 160. 相交链表.py ├── 1603. 设计停车系统.py ├── 1614. 括号的最大嵌套深度.py ├── 1630. 等差子数组.py ├── 1641. 统计字典序元音字符串的数目.py ├── 165. 比较版本号.py ├── 1662. 检查两个字符串数组是否相等.py ├── 167. 两数之和 II - 输入有序数组.py ├── 1672. 最富有客户的资产总量.py ├── 1678. 设计 Goal 解析器.py ├── 168. Excel表列名称.py ├── 1684. 统计一致字符串的数目.py ├── 1688. 比赛中的配对次数.py ├── 169. 多数元素.py ├── 1704. 判断字符串的两半是否相似.py ├── 171. Excel表列序号.py ├── 172. 阶乘后的零.py ├── 1720. 解码异或后的数组.py ├── 1732. 找到最高海拔.py ├── 1768. 交替合并字符串.py ├── 1773. 统计匹配检索规则的物品数量.py ├── 190. 颠倒二进制位.py ├── 191. 位1的个数.py ├── 2. 两数相加.py ├── 20. 有效的括号.py ├── 202. 快乐数.py ├── 204. 计数质数.py ├── 205. 同构字符串.py ├── 21. 合并两个有序链表.py ├── 217. 存在重复元素.py ├── 225. 用队列实现栈.py ├── 234. 回文链表.py ├── 237. 删除链表中的节点.py ├── 26. 删除有序数组中的重复项.py ├── 263. 丑数.py ├── 27. 移除元素.py ├── 28. 实现 strStr().py ├── 283. 移动零.py ├── 3. 无重复字符的最长子串.py ├── 300. 最长递增子序列.py ├── 303. 区域和检索 - 数组不可变.py ├── 304. 二维区域和检索 - 矩阵不可变.py ├── 326. 3的幂.py ├── 328. 奇偶链表.py ├── 341. 扁平化嵌套列表迭代器.py ├── 342. 4的幂.py ├── 344. 反转字符串.py ├── 345. 反转字符串中的元音字母.py ├── 35. 搜索插入位置.py ├── 357. 计算各个位数不同的数字个数.py ├── 38. 外观数列.py ├── 392. 判断子序列.py ├── 404. 左叶子之和.py ├── 409. 最长回文串.py ├── 41. 缺失的第一个正数.py ├── 412. Fizz Buzz.py ├── 442. 数组中重复的数据.py ├── 448. 找到所有数组中消失的数字.py ├── 461. 汉明距离.py ├── 5. 最长回文子串.py ├── 53. 最大子序和.py ├── 58. 最后一个单词的长度.py ├── 633. 平方数之和.py ├── 66. 加一.py ├── 67. 二进制求和.py ├── 69. x 的平方根.py ├── 697. 数组的度.py ├── 7. 整数反转.py ├── 70. 爬楼梯.py ├── 724. 寻找数组的中心下标.py ├── 73. 矩阵置零.py ├── 771. 宝石与石头.py ├── 83. 删除排序链表中的重复元素.py ├── 832. 翻转图像.py ├── 867. 转置矩阵.py ├── 88. 合并两个有序数组.py ├── 9. 回文数.py ├── LCP 01. 猜数字.py ├── LCP 06. 拿硬币.py ├── LCP 17. 速算机器人.py ├── 剑指 Offer 03. 数组中重复的数字.py ├── 剑指 Offer 05. 替换空格.py ├── 剑指 Offer 10- I. 斐波那契数列.py ├── 剑指 Offer 11. 旋转数组的最小数字.py ├── 剑指 Offer 17. 打印从1到最大的n位数.py ├── 剑指 Offer 39. 数组中出现次数超过一半的数字.py ├── 剑指 Offer 50. 第一个只出现一次的字符.py ├── 剑指 Offer 53 - II. 0~n-1中缺失的数字.py ├── 剑指 Offer 58 - II. 左旋转字符串.py ├── 面试题 01.01. 判定字符是否唯一.py ├── 面试题 01.02. 判定是否互为字符重排.py ├── 面试题 02.03. 删除中间节点.py └── 面试题 10.01. 合并排序的数组.py /.gitignore: -------------------------------------------------------------------------------- 1 | # visual studio code 2 | .vscode/ 3 | .idea/ 4 | 5 | # python 6 | venv/ 7 | virtualenv/ 8 | __pycache__ 9 | 10 | # misc 11 | .DS_Store 12 | 13 | # results 14 | *.npy 15 | *.npz 16 | *.png 17 | *.PNG 18 | *.jpg 19 | *.JPG 20 | *.jpeg 21 | 22 | # notebook checkpoints 23 | .ipynb_checkpoints 24 | 25 | # path -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # leetcode-python 2 | 3 | ![leetcode-python](https://socialify.git.ci/beiyuouo/leetcode-python/image?font=Source%20Code%20Pro&forks=1&issues=1&language=1&logo=https%3A%2F%2Favatars.githubusercontent.com%2Fu%2F44976445%3Fs%3D460%26u%3D182d335f502ab38522bde613717bd77aa1f6f766%26v%3D4&owner=1&pattern=Circuit%20Board&pulls=1&stargazers=1&theme=Light) 4 | 5 | # :wave: Hi 6 | 7 | LeetCode题Python代码 8 | 9 | 提升一下Python代码能力 0.0? 10 | 11 | 哪有什么做题啊,老板的任务罢了 -------------------------------------------------------------------------------- /code/1. 两数之和.py: -------------------------------------------------------------------------------- 1 | # Author: BeiYu 2 | # Github: https://github.com/beiyuouo 3 | # Date : 2021/3/22 12:29 4 | # Description: 5 | 6 | __author__ = "BeiYu" 7 | 8 | from typing import List 9 | 10 | 11 | class Solution: 12 | def twoSum(self, nums: List[int], target: int) -> List[int]: 13 | for i, n1 in enumerate(nums): 14 | for j, n2 in enumerate(nums[i + 1:]): 15 | if n1 + n2 == target: 16 | return [i, j + i + 1] 17 | -------------------------------------------------------------------------------- /code/100. 相同的树.py: -------------------------------------------------------------------------------- 1 | # Author: BeiYu 2 | # Github: https://github.com/beiyuouo 3 | # Date : 2021/4/3 16:12 4 | # Description: 5 | 6 | __author__ = "BeiYu" 7 | 8 | 9 | # Definition for a binary tree node. 10 | class TreeNode: 11 | def __init__(self, val=0, left=None, right=None): 12 | self.val = val 13 | self.left = left 14 | self.right = right 15 | 16 | 17 | class Solution: 18 | def isSameTree(self, p: TreeNode, q: TreeNode) -> bool: 19 | def _have(t): 20 | return t is not None 21 | 22 | if _have(p) != _have(q): return False 23 | if not _have(p): return True 24 | if p.val != q.val: return False 25 | 26 | if _have(p.left) != _have(q.left): return False 27 | if _have(p.right) != _have(q.right): return False 28 | 29 | flag = True 30 | if _have(p.left): 31 | flag = flag and self.isSameTree(p.left, q.left) 32 | 33 | if _have(p.right): 34 | flag = flag and self.isSameTree(p.right, q.right) 35 | 36 | return flag 37 | -------------------------------------------------------------------------------- /code/101. 对称二叉树.py: -------------------------------------------------------------------------------- 1 | # Author: BeiYu 2 | # Github: https://github.com/beiyuouo 3 | # Date : 2021/4/3 16:19 4 | # Description: 5 | 6 | __author__ = "BeiYu" 7 | 8 | 9 | # Definition for a binary tree node. 10 | class TreeNode: 11 | def __init__(self, val=0, left=None, right=None): 12 | self.val = val 13 | self.left = left 14 | self.right = right 15 | 16 | 17 | class Solution: 18 | def isSymmetric(self, root: TreeNode) -> bool: 19 | def _have(t): 20 | return t is not None 21 | 22 | def isSymmetry(p: TreeNode, q: TreeNode) -> bool: 23 | if _have(p) != _have(q): return False 24 | if not _have(p): return True 25 | if p.val != q.val: return False 26 | 27 | if _have(p.left) != _have(q.right): return False 28 | if _have(p.right) != _have(q.left): return False 29 | 30 | flag = True 31 | if _have(p.left): 32 | flag = flag and isSymmetry(p.left, q.right) 33 | 34 | if _have(p.right): 35 | flag = flag and isSymmetry(p.right, q.left) 36 | 37 | return flag 38 | 39 | if not _have(root): return True 40 | if _have(root.left) != _have(root.right): return False 41 | if _have(root.left): return isSymmetry(root.left, root.right) 42 | return True 43 | -------------------------------------------------------------------------------- /code/1013. 将数组分成和相等的三个部分.py: -------------------------------------------------------------------------------- 1 | # Author: BeiYu 2 | # Github: https://github.com/beiyuouo 3 | # Date : 2021/4/24 01:14 4 | # Description: 5 | 6 | __author__ = "BeiYu" 7 | 8 | from typing import List 9 | 10 | 11 | class Solution: 12 | def canThreePartsEqualSum(self, arr: List[int]) -> bool: 13 | pre_sum = [arr[0]] 14 | 15 | for i in range(1, len(arr)): 16 | tmp = arr[i] + pre_sum[-1] 17 | pre_sum.append(tmp) 18 | 19 | def _get_psum(idx: int) -> int: 20 | if idx < 0 or idx > len(pre_sum): 21 | return 0 22 | return pre_sum[idx] 23 | 24 | def _get_sum(lidx: int, ridx: int) -> int: 25 | return _get_psum(ridx) - _get_psum(lidx - 1) 26 | # print(pre_sum) 27 | for i in range(len(arr)-2): 28 | if _get_sum(0, i) * 2 == _get_sum(i + 1, len(arr) - 1): 29 | for j in range(i+1, len(arr)-1): 30 | if _get_sum(i+1, j) == _get_sum(j+1, len(arr)-1): 31 | return True 32 | 33 | # fuck, i forget that negative numbers are exist in array, so that the prefix 34 | # sum doesn't have monotonicity. 35 | # l, r = i + 1, len(arr) - 1 36 | # while l <= r: 37 | # mid = (l + r) // 2 38 | # if _get_sum(i + 1, mid) < _get_sum(mid + 1, len(arr) - 1): 39 | # l = mid + 1 40 | # else: 41 | # r = mid - 1 42 | # print(i, l, r) 43 | # if _get_sum(i + 1, l) == _get_sum(l + 1, len(arr) - 1): 44 | # return True 45 | 46 | return False 47 | -------------------------------------------------------------------------------- /code/104. 二叉树的最大深度.py: -------------------------------------------------------------------------------- 1 | # Author: BeiYu 2 | # Github: https://github.com/beiyuouo 3 | # Date : 2021/4/3 16:26 4 | # Description: 5 | 6 | __author__ = "BeiYu" 7 | 8 | 9 | # Definition for a binary tree node. 10 | class TreeNode: 11 | def __init__(self, val=0, left=None, right=None): 12 | self.val = val 13 | self.left = left 14 | self.right = right 15 | 16 | 17 | class Solution: 18 | def maxDepth(self, root: TreeNode) -> int: 19 | if not root: return 0 20 | return max(1, self.maxDepth(root.left) + 1, self.maxDepth(root.right) + 1) 21 | -------------------------------------------------------------------------------- /code/108. 将有序数组转换为二叉搜索树.py: -------------------------------------------------------------------------------- 1 | # Author: BeiYu 2 | # Github: https://github.com/beiyuouo 3 | # Date : 2021/4/4 16:29 4 | # Description: 5 | 6 | __author__ = "BeiYu" 7 | 8 | # Definition for a binary tree node. 9 | from typing import List 10 | 11 | 12 | class TreeNode: 13 | def __init__(self, val=0, left=None, right=None): 14 | self.val = val 15 | self.left = left 16 | self.right = right 17 | 18 | 19 | class Solution: 20 | def sortedArrayToBST(self, nums: List[int]) -> TreeNode: 21 | if len(nums) == 0: return None 22 | mid = len(nums) // 2 23 | root = TreeNode(nums[mid]) 24 | 25 | root.left = self.sortedArrayToBST(nums[:mid]) 26 | root.right = self.sortedArrayToBST(nums[mid+1:]) 27 | 28 | return root 29 | -------------------------------------------------------------------------------- /code/1089. 复写零.py: -------------------------------------------------------------------------------- 1 | # Author: BeiYu 2 | # Github: https://github.com/beiyuouo 3 | # Date : 2021/4/11 16:45 4 | # Description: 5 | 6 | __author__ = "BeiYu" 7 | 8 | from typing import List 9 | 10 | 11 | class Solution: 12 | def duplicateZeros(self, arr: List[int]) -> None: 13 | """ 14 | Do not return anything, modify arr in-place instead. 15 | """ 16 | n = len(arr) 17 | new_arr = [] 18 | for i in range(n): 19 | if arr[i] == 0: 20 | new_arr.append(0) 21 | new_arr.append(arr[i]) 22 | if len(new_arr) >= n: 23 | break 24 | 25 | arr[:] = new_arr[:n] 26 | -------------------------------------------------------------------------------- /code/110. 平衡二叉树.py: -------------------------------------------------------------------------------- 1 | # Author: BeiYu 2 | # Github: https://github.com/beiyuouo 3 | # Date : 2021/4/4 16:40 4 | # Description: 5 | 6 | __author__ = "BeiYu" 7 | 8 | 9 | # Definition for a binary tree node. 10 | class TreeNode: 11 | def __init__(self, val=0, left=None, right=None): 12 | self.val = val 13 | self.left = left 14 | self.right = right 15 | 16 | 17 | class Solution: 18 | def __init__(self): 19 | self.dep = {} 20 | self.dep[None] = 0 21 | 22 | def isBalanced(self, root: TreeNode) -> bool: 23 | if not root: return True 24 | 25 | if not self.isBalanced(root.left) or not self.isBalanced(root.right): 26 | return False 27 | 28 | self.dep[root] = max(0, self.dep[root.left], self.dep[root.right]) + 1 29 | 30 | # print(f'{root.val} -> {self.dep[root]}, {self.dep[root.left]}, {self.dep[root.right]}') 31 | 32 | if abs(self.dep[root.left] - self.dep[root.right]) > 1: 33 | return False 34 | 35 | return True 36 | -------------------------------------------------------------------------------- /code/1103. 分糖果 II.py: -------------------------------------------------------------------------------- 1 | # Author: BeiYu 2 | # Github: https://github.com/beiyuouo 3 | # Date : 2021/4/11 16:03 4 | # Description: 5 | 6 | __author__ = "BeiYu" 7 | 8 | from typing import List 9 | 10 | 11 | class Solution: 12 | def distributeCandies(self, candies: int, num_people: int) -> List[int]: 13 | _one = (1 + num_people) * num_people // 2 14 | 15 | import math 16 | 17 | l, r = 0, candies 18 | 19 | def _calc_can(x: int) -> int: 20 | return (1 + num_people * x) * num_people * x // 2 21 | 22 | while l <= r: 23 | mid = (l + r) // 2 24 | if _calc_can(mid) <= candies: 25 | l = mid + 1 26 | else: 27 | r = mid - 1 28 | 29 | res = [(i + 1) * r + num_people * (0 + r - 1) * r // 2 for i in range(num_people)] 30 | candies -= sum(res) 31 | 32 | _now = num_people * r + 1 33 | idx = 0 34 | while candies > 0: 35 | res[idx] += min(candies, _now) 36 | candies -= min(candies, _now) 37 | _now += 1 38 | idx += 1 39 | 40 | return res 41 | -------------------------------------------------------------------------------- /code/1108. IP 地址无效化.py: -------------------------------------------------------------------------------- 1 | # Author: BeiYu 2 | # Github: https://github.com/beiyuouo 3 | # Date : 2021/3/15 14:07 4 | # Description: 5 | 6 | __author__ = "BeiYu" 7 | 8 | 9 | class Solution: 10 | def defangIPaddr(self, address: str) -> str: 11 | return address.replace(".", "[.]") 12 | -------------------------------------------------------------------------------- /code/111. 二叉树的最小深度.py: -------------------------------------------------------------------------------- 1 | # Author: BeiYu 2 | # Github: https://github.com/beiyuouo 3 | # Date : 2021/4/5 17:25 4 | # Description: 5 | 6 | __author__ = "BeiYu" 7 | 8 | 9 | # Definition for a binary tree node. 10 | class TreeNode: 11 | def __init__(self, val=0, left=None, right=None): 12 | self.val = val 13 | self.left = left 14 | self.right = right 15 | 16 | 17 | class Solution: 18 | def minDepth(self, root: TreeNode) -> int: 19 | if not root: return 0 20 | 21 | def _have(x): 22 | return x is not None 23 | 24 | if _have(root.left) and _have(root.right): 25 | return min(self.minDepth(root.left), self.minDepth(root.right)) + 1 26 | 27 | if _have(root.left): return self.minDepth(root.left) 28 | 29 | if _have(root.right): return self.minDepth(root.right) 30 | 31 | return 1 32 | -------------------------------------------------------------------------------- /code/1114. 按序打印.py: -------------------------------------------------------------------------------- 1 | # Author: BeiYu 2 | # Github: https://github.com/beiyuouo 3 | # Date : 2021/4/11 15:56 4 | # Description: 5 | 6 | __author__ = "BeiYu" 7 | 8 | 9 | class Foo: 10 | def __init__(self): 11 | self.ok_first = False 12 | self.ok_second = False 13 | 14 | def first(self, printFirst: 'Callable[[], None]') -> None: 15 | # printFirst() outputs "first". Do not change or remove this line. 16 | printFirst() 17 | self.ok_first = True 18 | 19 | def second(self, printSecond: 'Callable[[], None]') -> None: 20 | # printSecond() outputs "second". Do not change or remove this line. 21 | while not self.ok_first: pass 22 | printSecond() 23 | self.ok_second = True 24 | 25 | def third(self, printThird: 'Callable[[], None]') -> None: 26 | # printThird() outputs "third". Do not change or remove this line. 27 | while not self.ok_first or not self.ok_second: pass 28 | printThird() 29 | -------------------------------------------------------------------------------- /code/112. 路径总和.py: -------------------------------------------------------------------------------- 1 | # Author: BeiYu 2 | # Github: https://github.com/beiyuouo 3 | # Date : 2021/4/5 17:37 4 | # Description: 5 | 6 | __author__ = "BeiYu" 7 | 8 | 9 | # Definition for a binary tree node. 10 | class TreeNode: 11 | def __init__(self, val=0, left=None, right=None): 12 | self.val = val 13 | self.left = left 14 | self.right = right 15 | 16 | 17 | class Solution: 18 | def hasPathSum(self, root: TreeNode, targetSum: int) -> bool: 19 | if not root: return False 20 | 21 | def is_leaf(x: TreeNode): 22 | if x.left or x.right: return False 23 | return True 24 | 25 | global flag 26 | flag = False 27 | 28 | def dfs(x: TreeNode, tot: int): 29 | if is_leaf(x): 30 | global flag 31 | if tot + x.val == targetSum: flag = True 32 | return 33 | 34 | if x.left: dfs(x.left, tot + x.val) 35 | if x.right: dfs(x.right, tot + x.val) 36 | 37 | dfs(root, 0) 38 | 39 | return flag 40 | -------------------------------------------------------------------------------- /code/1160. 拼写单词.py: -------------------------------------------------------------------------------- 1 | # Author: BeiYu 2 | # Github: https://github.com/beiyuouo 3 | # Date : 2021/4/14 01:34 4 | # Description: 5 | 6 | __author__ = "BeiYu" 7 | 8 | from typing import List, Dict 9 | 10 | 11 | class Solution: 12 | def countCharacters(self, words: List[str], chars: str) -> int: 13 | 14 | def get_dic(strs: str) -> Dict: 15 | dic = {} 16 | for chs in strs: 17 | if chs not in dic.keys(): 18 | dic[chs] = 0 19 | dic[chs] += 1 20 | return dic 21 | 22 | chars_dic = get_dic(chars) 23 | res = 0 24 | for word in words: 25 | word_dic = get_dic(word) 26 | 27 | def check(_char_dic: Dict, _word_dic: Dict) -> bool: 28 | for key in _word_dic: 29 | if key not in _char_dic or _char_dic[key] < _word_dic[key]: 30 | return False 31 | 32 | return True 33 | 34 | if check(chars_dic, word_dic): 35 | res += len(word) 36 | 37 | return res 38 | -------------------------------------------------------------------------------- /code/118. 杨辉三角.py: -------------------------------------------------------------------------------- 1 | # Author: BeiYu 2 | # Github: https://github.com/beiyuouo 3 | # Date : 2021/4/5 17:39 4 | # Description: 5 | 6 | __author__ = "BeiYu" 7 | 8 | from typing import List 9 | 10 | 11 | class Solution: 12 | def generate(self, numRows: int) -> List[List[int]]: 13 | res = [] 14 | res.append([1]) 15 | for i in range(1, numRows): 16 | new_row = [1] 17 | for j in range(i - 1): 18 | new_row.append(res[-1][j] + res[-1][j + 1]) 19 | new_row.append(1) 20 | res.append(new_row) 21 | 22 | return res 23 | -------------------------------------------------------------------------------- /code/119. 杨辉三角 II.py: -------------------------------------------------------------------------------- 1 | # Author: BeiYu 2 | # Github: https://github.com/beiyuouo 3 | # Date : 2021/4/6 18:50 4 | # Description: 5 | 6 | __author__ = "BeiYu" 7 | 8 | from typing import List 9 | 10 | 11 | class Solution: 12 | def getRow(self, rowIndex: int) -> List[int]: 13 | p = [1] 14 | for i in range(1, rowIndex + 1): 15 | p.append(p[-1] * i) 16 | 17 | def C(n, m): 18 | return p[n] // p[m] // p[n - m] 19 | 20 | res = [] 21 | for i in range(rowIndex + 1): 22 | res.append(C(rowIndex, i)) 23 | 24 | return res 25 | -------------------------------------------------------------------------------- /code/121. 买卖股票的最佳时机.py: -------------------------------------------------------------------------------- 1 | # Author: BeiYu 2 | # Github: https://github.com/beiyuouo 3 | # Date : 2021/4/6 18:55 4 | # Description: 5 | 6 | __author__ = "BeiYu" 7 | 8 | from typing import List 9 | 10 | 11 | class Solution: 12 | def maxProfit(self, prices: List[int]) -> int: 13 | maxOut = prices[-1] 14 | res = 0 15 | for i in range(len(prices) - 1, -1, -1): 16 | res = max(res, maxOut - prices[i]) 17 | maxOut = max(maxOut, prices[i]) 18 | 19 | return res 20 | -------------------------------------------------------------------------------- /code/122. 买卖股票的最佳时机 II.py: -------------------------------------------------------------------------------- 1 | # Author: BeiYu 2 | # Github: https://github.com/beiyuouo 3 | # Date : 2021/4/6 19:05 4 | # Description: 5 | 6 | __author__ = "BeiYu" 7 | 8 | from typing import List 9 | 10 | 11 | class Solution: 12 | def maxProfit(self, prices: List[int]) -> int: 13 | res = 0 14 | for i in range(1, len(prices)): 15 | if prices[i] - prices[i - 1] > 0: 16 | res += prices[i] - prices[i - 1] 17 | 18 | return res 19 | -------------------------------------------------------------------------------- /code/125. 验证回文串.py: -------------------------------------------------------------------------------- 1 | # Author: BeiYu 2 | # Github: https://github.com/beiyuouo 3 | # Date : 2021/4/7 19:07 4 | # Description: 5 | 6 | __author__ = "BeiYu" 7 | 8 | 9 | class Solution: 10 | def isPalindrome(self, s: str) -> bool: 11 | s = ''.join(filter(str.isalnum, s.lower())) 12 | return s == s[::-1] 13 | -------------------------------------------------------------------------------- /code/1266. 访问所有点的最小时间.py: -------------------------------------------------------------------------------- 1 | # Author: BeiYu 2 | # Github: https://github.com/beiyuouo 3 | # Date : 2021/3/19 16:36 4 | # Description: 5 | 6 | __author__ = "BeiYu" 7 | 8 | from typing import List 9 | 10 | 11 | class Solution: 12 | def minTimeToVisitAllPoints(self, points: List[List[int]]) -> int: 13 | def _get_time(p1: List[int], p2: List[int]): 14 | dx, dy = abs(p1[0] - p2[0]), abs(p1[1] - p2[1]) 15 | return max(dx, dy) 16 | 17 | res = 0 18 | for i in range(len(points) - 1): 19 | res += _get_time(points[i], points[i + 1]) 20 | return res 21 | -------------------------------------------------------------------------------- /code/1281. 整数的各位积和之差.py: -------------------------------------------------------------------------------- 1 | # Author: BeiYu 2 | # Github: https://github.com/beiyuouo 3 | # Date : 2021/3/17 14:20 4 | # Description: 5 | 6 | __author__ = "BeiYu" 7 | 8 | 9 | class Solution: 10 | def subtractProductAndSum(self, n: int) -> int: 11 | def _calc_sum(s: str): 12 | res = 0 13 | for ch in s: 14 | res += int(ch) 15 | return res 16 | 17 | def _calc_mul(s: str): 18 | res = 1 19 | for ch in s: 20 | res *= int(ch) 21 | return res 22 | 23 | return _calc_mul(str(n)) - _calc_sum(str(n)) 24 | -------------------------------------------------------------------------------- /code/1290. 二进制链表转整数.py: -------------------------------------------------------------------------------- 1 | # Author: BeiYu 2 | # Github: https://github.com/beiyuouo 3 | # Date : 2021/3/19 16:55 4 | # Description: 5 | 6 | __author__ = "BeiYu" 7 | 8 | 9 | # Definition for singly-linked list. 10 | class ListNode: 11 | def __init__(self, x): 12 | self.val = x 13 | self.next = None 14 | 15 | 16 | class Solution: 17 | def getDecimalValue(self, head: ListNode) -> int: 18 | res = 0 19 | while head: 20 | res = res * 2 + head.val 21 | head = head.next 22 | return res 23 | -------------------------------------------------------------------------------- /code/1295. 统计位数为偶数的数字.py: -------------------------------------------------------------------------------- 1 | # Author: BeiYu 2 | # Github: https://github.com/beiyuouo 3 | # Date : 2021/3/19 16:44 4 | # Description: 5 | 6 | __author__ = "BeiYu" 7 | 8 | from typing import List 9 | 10 | 11 | class Solution: 12 | def findNumbers(self, nums: List[int]) -> int: 13 | cnt = 0 14 | for num in nums: 15 | if len(str(num)) % 2 == 0: 16 | cnt += 1 17 | return cnt 18 | -------------------------------------------------------------------------------- /code/13. 罗马数字转整数.py: -------------------------------------------------------------------------------- 1 | # Author: BeiYu 2 | # Github: https://github.com/beiyuouo 3 | # Date : 2021/3/28 00:45 4 | # Description: 5 | 6 | __author__ = "BeiYu" 7 | 8 | 9 | class Solution: 10 | def romanToInt(self, s: str) -> int: 11 | word_to_int = {'I': 1, 'V': 5, 'X': 10, 'L': 50, 'C': 100, 'D': 500, 'M': 1000} 12 | cur = 0 13 | 14 | def _getnextchar(idx: int): 15 | if idx + 1 >= len(s): 16 | return None 17 | return s[idx + 1] 18 | 19 | for i in range(len(s)): 20 | if (s[i] == 'I' and (_getnextchar(i) == 'V' or _getnextchar(i) == 'X')) \ 21 | or (s[i] == 'X' and (_getnextchar(i) == 'L' or _getnextchar(i) == 'C')) \ 22 | or (s[i] == 'C' and (_getnextchar(i) == 'D' or _getnextchar(i) == 'M')): 23 | cur -= word_to_int[s[i]] 24 | else: 25 | cur += word_to_int[s[i]] 26 | 27 | return cur 28 | -------------------------------------------------------------------------------- /code/1313. 解压缩编码列表.py: -------------------------------------------------------------------------------- 1 | # Author: BeiYu 2 | # Github: https://github.com/beiyuouo 3 | # Date : 2021/3/17 14:21 4 | # Description: 5 | 6 | __author__ = "BeiYu" 7 | 8 | from typing import List 9 | 10 | 11 | class Solution: 12 | def decompressRLElist(self, nums: List[int]) -> List[int]: 13 | res = [] 14 | for i in range(0, len(nums), 2): 15 | res.extend([nums[i + 1] for x in range(nums[i])]) 16 | return res 17 | 18 | 19 | if __name__ == '__main__': 20 | solution = Solution() 21 | print(solution.decompressRLElist([1, 2, 3, 4])) 22 | -------------------------------------------------------------------------------- /code/1342. 将数字变成 0 的操作次数.py: -------------------------------------------------------------------------------- 1 | # Author: BeiYu 2 | # Github: https://github.com/beiyuouo 3 | # Date : 2021/3/19 16:44 4 | # Description: 5 | 6 | __author__ = "BeiYu" 7 | 8 | 9 | class Solution: 10 | def numberOfSteps(self, num: int) -> int: 11 | cnt = 0 12 | while num: 13 | if num % 2 == 0: 14 | num = num // 2 15 | else: 16 | num = num - 1 17 | cnt += 1 18 | return cnt 19 | -------------------------------------------------------------------------------- /code/136. 只出现一次的数字.py: -------------------------------------------------------------------------------- 1 | # Author: BeiYu 2 | # Github: https://github.com/beiyuouo 3 | # Date : 2021/4/7 19:52 4 | # Description: 5 | 6 | __author__ = "BeiYu" 7 | 8 | from typing import List 9 | 10 | 11 | class Solution: 12 | def singleNumber(self, nums: List[int]) -> int: 13 | for i in range(1, len(nums)): 14 | nums[0] = nums[0] ^ nums[i] 15 | return nums[0] 16 | -------------------------------------------------------------------------------- /code/1365. 有多少小于当前数字的数字.py: -------------------------------------------------------------------------------- 1 | # Author: BeiYu 2 | # Github: https://github.com/beiyuouo 3 | # Date : 2021/3/17 14:33 4 | # Description: 5 | 6 | __author__ = "BeiYu" 7 | 8 | from typing import List 9 | 10 | 11 | class Solution: 12 | def smallerNumbersThanCurrent(self, nums: List[int]) -> List[int]: 13 | def _calc(x: int) -> int: 14 | cnt = 0 15 | for i in nums: 16 | if i < x: 17 | cnt += 1 18 | return cnt 19 | 20 | res = [] 21 | for num in nums: 22 | res.append(_calc(num)) 23 | 24 | return res 25 | -------------------------------------------------------------------------------- /code/138. 复制带随机指针的链表.py: -------------------------------------------------------------------------------- 1 | """ 2 | # Definition for a Node. 3 | class Node: 4 | def __init__(self, x: int, next: 'Node' = None, random: 'Node' = None): 5 | self.val = int(x) 6 | self.next = next 7 | self.random = random 8 | """ 9 | 10 | from copy import copy 11 | 12 | class Solution: 13 | def copyRandomList(self, head: 'Node') -> 'Node': 14 | addr2id = {} 15 | 16 | q = head 17 | count = 0 18 | 19 | while q: 20 | addr2id[q] = count 21 | count += 1 22 | q = q.next 23 | 24 | q = head 25 | count = 0 26 | id2addr = {} 27 | 28 | while q: 29 | temp_ = copy(q) 30 | id2addr[count] = temp_ 31 | count += 1 32 | q = q.next 33 | 34 | id2addr[count] = None 35 | 36 | q = head 37 | count = 0 38 | while q: 39 | id2addr[count].next = id2addr[count + 1] 40 | if q.random: 41 | id2addr[count].random = id2addr[addr2id[q.random]] 42 | count += 1 43 | q = q.next 44 | 45 | return id2addr[0] 46 | 47 | 48 | -------------------------------------------------------------------------------- /code/1389. 按既定顺序创建目标数组.py: -------------------------------------------------------------------------------- 1 | # Author: BeiYu 2 | # Github: https://github.com/beiyuouo 3 | # Date : 2021/3/17 14:21 4 | # Description: 5 | 6 | __author__ = "BeiYu" 7 | 8 | from typing import List 9 | 10 | 11 | class Solution: 12 | def createTargetArray(self, nums: List[int], index: List[int]) -> List[int]: 13 | target = [] 14 | for i in range(len(nums)): 15 | target.insert(index[i], nums[i]) 16 | return target 17 | -------------------------------------------------------------------------------- /code/14. 最长公共前缀.py: -------------------------------------------------------------------------------- 1 | # Author: BeiYu 2 | # Github: https://github.com/beiyuouo 3 | # Date : 2021/3/28 00:57 4 | # Description: 5 | 6 | __author__ = "BeiYu" 7 | 8 | from typing import List 9 | 10 | 11 | class Solution: 12 | def longestCommonPrefix(self, strs: List[str]) -> str: 13 | if len(strs) == 0: 14 | return "" 15 | min_len = len(strs[0]) 16 | for i in range(len(strs)): 17 | min_len = min(min_len, len(strs[i])) 18 | 19 | ans = "" 20 | 21 | for i in range(min_len, -1, -1): 22 | prefix = strs[0][:i + 1] 23 | flag = True 24 | for ss in strs: 25 | if not ss.startswith(prefix): 26 | flag = False 27 | break 28 | 29 | if flag: 30 | ans = prefix 31 | break 32 | 33 | return ans 34 | -------------------------------------------------------------------------------- /code/141. 环形链表.py: -------------------------------------------------------------------------------- 1 | # Author: BeiYu 2 | # Github: https://github.com/beiyuouo 3 | # Date : 2021/4/7 19:59 4 | # Description: 5 | 6 | __author__ = "BeiYu" 7 | 8 | 9 | # Definition for singly-linked list. 10 | class ListNode: 11 | def __init__(self, x): 12 | self.val = x 13 | self.next = None 14 | 15 | 16 | class Solution: 17 | def hasCycle(self, head: ListNode) -> bool: 18 | p = head 19 | while p: 20 | if p.next == -1: return True 21 | q = p.next 22 | p.next = -1 23 | p = q 24 | return False 25 | -------------------------------------------------------------------------------- /code/1431. 拥有最多糖果的孩子.py: -------------------------------------------------------------------------------- 1 | # Author: BeiYu 2 | # Github: https://github.com/beiyuouo 3 | # Date : 2021/3/22 13:44 4 | # Description: 5 | 6 | __author__ = "BeiYu" 7 | 8 | from typing import List 9 | 10 | 11 | class Solution: 12 | def kidsWithCandies(self, candies: List[int], extraCandies: int) -> List[bool]: 13 | res = [] 14 | max_candies = max(candies) 15 | for i in range(len(candies)): 16 | if candies[i] + extraCandies < max_candies: 17 | res.append(False) 18 | else: 19 | res.append(True) 20 | return res 21 | -------------------------------------------------------------------------------- /code/1450. 在既定时间做作业的学生人数.py: -------------------------------------------------------------------------------- 1 | # Author: BeiYu 2 | # Github: https://github.com/beiyuouo 3 | # Date : 2021/3/21 17:07 4 | # Description: 5 | 6 | __author__ = "BeiYu" 7 | 8 | from typing import List 9 | 10 | 11 | class Solution: 12 | def busyStudent(self, startTime: List[int], endTime: List[int], queryTime: int) -> int: 13 | cnt = 0 14 | for i in range(len(startTime)): 15 | if startTime[i] <= queryTime <= endTime[i]: 16 | cnt += 1 17 | return cnt 18 | -------------------------------------------------------------------------------- /code/1470. 重新排列数组.py: -------------------------------------------------------------------------------- 1 | # Author: BeiYu 2 | # Github: https://github.com/beiyuouo 3 | # Date : 2021/3/14 13:52 4 | # Description: 5 | 6 | __author__ = "BeiYu" 7 | 8 | from typing import List 9 | 10 | 11 | class Solution: 12 | def shuffle(self, nums: List[int], n: int) -> List[int]: 13 | _nums = [] 14 | for i in range(n): 15 | _nums.append(nums[i]) 16 | _nums.append(nums[i + n]) 17 | return _nums 18 | -------------------------------------------------------------------------------- /code/1480. 一维数组的动态和.py: -------------------------------------------------------------------------------- 1 | from typing import * 2 | 3 | 4 | class Solution: 5 | def runningSum(self, nums: List[int]) -> List[int]: 6 | res = [] 7 | tot = 0 8 | for i in nums: 9 | tot += i 10 | res.append(tot) 11 | return res 12 | -------------------------------------------------------------------------------- /code/1486. 数组异或操作.py: -------------------------------------------------------------------------------- 1 | # Author: BeiYu 2 | # Github: https://github.com/beiyuouo 3 | # Date : 2021/3/14 13:56 4 | # Description: 5 | 6 | __author__ = "BeiYu" 7 | 8 | 9 | class Solution: 10 | def xorOperation(self, n: int, start: int) -> int: 11 | res = 0 12 | for i in range(n): 13 | res = res ^ (start + 2 * i) 14 | return res 15 | -------------------------------------------------------------------------------- /code/15. 三数之和.py: -------------------------------------------------------------------------------- 1 | # Author: BeiYu 2 | # Github: https://github.com/beiyuouo 3 | # Date : 2021/4/24 00:46 4 | # Description: 5 | 6 | __author__ = "BeiYu" 7 | 8 | from copy import copy 9 | from typing import List 10 | 11 | # TODO: O(n2logn) can not accept this problem 12 | 13 | 14 | class Solution: 15 | def threeSum(self, nums: List[int]) -> List[List[int]]: 16 | if len(nums) < 3: 17 | return [] 18 | 19 | res = [] 20 | nums.sort() 21 | 22 | # a + b + c = 0 23 | for i in range(len(nums)): 24 | if nums[i] > 0: 25 | break 26 | if i > 0 and nums[i] == nums[i - 1]: 27 | continue 28 | pl, pr = i + 1, len(nums) - 1 29 | while pl < pr: 30 | if nums[i] + nums[pl] + nums[pr] == 0: 31 | res.append([nums[i], nums[pl], nums[pr]]) 32 | pl += 1 33 | pr -= 1 34 | while pl < pr and nums[pl] == nums[pl - 1]: 35 | pl += 1 36 | while pl < pr and nums[pr] == nums[pr + 1]: 37 | pr -= 1 38 | elif nums[i] + nums[pl] + nums[pr] > 0: 39 | pr -= 1 40 | else: 41 | pl += 1 42 | 43 | return res 44 | 45 | 46 | if __name__ == "__main__": 47 | inputs = [ 48 | 82597, 49 | -9243, 50 | 62390, 51 | 83030, 52 | -97960, 53 | -26521, 54 | -61011, 55 | 83390, 56 | -38677, 57 | 12333, 58 | 75987, 59 | 46091, 60 | 83794, 61 | 19355, 62 | -71037, 63 | -6242, 64 | -28801, 65 | 324, 66 | 1202, 67 | -90885, 68 | -2989, 69 | -95597, 70 | -34333, 71 | 35528, 72 | 5680, 73 | 89093, 74 | -90606, 75 | 50360, 76 | -29393, 77 | -27012, 78 | 53313, 79 | 65213, 80 | 99818, 81 | -82405, 82 | -41661, 83 | -3333, 84 | -51952, 85 | 72135, 86 | -1523, 87 | 26377, 88 | 74685, 89 | 96992, 90 | 92263, 91 | 15929, 92 | 5467, 93 | -99555, 94 | -43348, 95 | -41689, 96 | -60383, 97 | -3990, 98 | 32165, 99 | 65265, 100 | -72973, 101 | -58372, 102 | 12741, 103 | -48568, 104 | -46596, 105 | 72419, 106 | -1859, 107 | 34153, 108 | 62937, 109 | 81310, 110 | -61823, 111 | -96770, 112 | -54944, 113 | 8845, 114 | -91184, 115 | 24208, 116 | -29078, 117 | 31495, 118 | 65258, 119 | 14198, 120 | 85395, 121 | 70506, 122 | -40908, 123 | 56740, 124 | -12228, 125 | -40072, 126 | 32429, 127 | 93001, 128 | 68445, 129 | -73927, 130 | 25731, 131 | -91859, 132 | -24150, 133 | 10093, 134 | -60271, 135 | -81683, 136 | -18126, 137 | 51055, 138 | 48189, 139 | -6468, 140 | 25057, 141 | 81194, 142 | -58628, 143 | 74042, 144 | 66158, 145 | -14452, 146 | -49851, 147 | -43667, 148 | 11092, 149 | 39189, 150 | -17025, 151 | -79173, 152 | 13606, 153 | 83172, 154 | 92647, 155 | -59741, 156 | 19343, 157 | -26644, 158 | -57607, 159 | 82908, 160 | -20655, 161 | 1637, 162 | 80060, 163 | 98994, 164 | 39331, 165 | -31274, 166 | -61523, 167 | 91225, 168 | -72953, 169 | 13211, 170 | -75116, 171 | -98421, 172 | -41571, 173 | -69074, 174 | 99587, 175 | 39345, 176 | 42151, 177 | -2460, 178 | 98236, 179 | 15690, 180 | -52507, 181 | -95803, 182 | -48935, 183 | -46492, 184 | -45606, 185 | -79254, 186 | -99851, 187 | 52533, 188 | 73486, 189 | 39948, 190 | -7240, 191 | 71815, 192 | -585, 193 | -96252, 194 | 90990, 195 | -93815, 196 | 93340, 197 | -71848, 198 | 58733, 199 | -14859, 200 | -83082, 201 | -75794, 202 | -82082, 203 | -24871, 204 | -15206, 205 | 91207, 206 | -56469, 207 | -93618, 208 | 67131, 209 | -8682, 210 | 75719, 211 | 87429, 212 | -98757, 213 | -7535, 214 | -24890, 215 | -94160, 216 | 85003, 217 | 33928, 218 | 75538, 219 | 97456, 220 | -66424, 221 | -60074, 222 | -8527, 223 | -28697, 224 | -22308, 225 | 2246, 226 | -70134, 227 | -82319, 228 | -10184, 229 | 87081, 230 | -34949, 231 | -28645, 232 | -47352, 233 | -83966, 234 | -60418, 235 | -15293, 236 | -53067, 237 | -25921, 238 | 55172, 239 | 75064, 240 | 95859, 241 | 48049, 242 | 34311, 243 | -86931, 244 | -38586, 245 | 33686, 246 | -36714, 247 | 96922, 248 | 76713, 249 | -22165, 250 | -80585, 251 | -34503, 252 | -44516, 253 | 39217, 254 | -28457, 255 | 47227, 256 | -94036, 257 | 43457, 258 | 24626, 259 | -87359, 260 | 26898, 261 | -70819, 262 | 30528, 263 | -32397, 264 | -69486, 265 | 84912, 266 | -1187, 267 | -98986, 268 | -32958, 269 | 4280, 270 | -79129, 271 | -65604, 272 | 9344, 273 | 58964, 274 | 50584, 275 | 71128, 276 | -55480, 277 | 24986, 278 | 15086, 279 | -62360, 280 | -42977, 281 | -49482, 282 | -77256, 283 | -36895, 284 | -74818, 285 | 20, 286 | 3063, 287 | -49426, 288 | 28152, 289 | -97329, 290 | 6086, 291 | 86035, 292 | -88743, 293 | 35241, 294 | 44249, 295 | 19927, 296 | -10660, 297 | 89404, 298 | 24179, 299 | -26621, 300 | -6511, 301 | 57745, 302 | -28750, 303 | 96340, 304 | -97160, 305 | -97822, 306 | -49979, 307 | 52307, 308 | 79462, 309 | 94273, 310 | -24808, 311 | 77104, 312 | 9255, 313 | -83057, 314 | 77655, 315 | 21361, 316 | 55956, 317 | -9096, 318 | 48599, 319 | -40490, 320 | -55107, 321 | 2689, 322 | 29608, 323 | 20497, 324 | 66834, 325 | -34678, 326 | 23553, 327 | -81400, 328 | -66630, 329 | -96321, 330 | -34499, 331 | -12957, 332 | -20564, 333 | 25610, 334 | -4322, 335 | -58462, 336 | 20801, 337 | 53700, 338 | 71527, 339 | 24669, 340 | -54534, 341 | 57879, 342 | -3221, 343 | 33636, 344 | 3900, 345 | 97832, 346 | -27688, 347 | -98715, 348 | 5992, 349 | 24520, 350 | -55401, 351 | -57613, 352 | -69926, 353 | 57377, 354 | -77610, 355 | 20123, 356 | 52174, 357 | 860, 358 | 60429, 359 | -91994, 360 | -62403, 361 | -6218, 362 | -90610, 363 | -37263, 364 | -15052, 365 | 62069, 366 | -96465, 367 | 44254, 368 | 89892, 369 | -3406, 370 | 19121, 371 | -41842, 372 | -87783, 373 | -64125, 374 | -56120, 375 | 73904, 376 | -22797, 377 | -58118, 378 | -4866, 379 | 5356, 380 | 75318, 381 | 46119, 382 | 21276, 383 | -19246, 384 | -9241, 385 | -97425, 386 | 57333, 387 | -15802, 388 | 93149, 389 | 25689, 390 | -5532, 391 | 95716, 392 | 39209, 393 | -87672, 394 | -29470, 395 | -16324, 396 | -15331, 397 | 27632, 398 | -39454, 399 | 56530, 400 | -16000, 401 | 29853, 402 | 46475, 403 | 78242, 404 | -46602, 405 | 83192, 406 | -73440, 407 | -15816, 408 | 50964, 409 | -36601, 410 | 89758, 411 | 38375, 412 | -40007, 413 | -36675, 414 | -94030, 415 | 67576, 416 | 46811, 417 | -64919, 418 | 45595, 419 | 76530, 420 | 40398, 421 | 35845, 422 | 41791, 423 | 67697, 424 | -30439, 425 | -82944, 426 | 63115, 427 | 33447, 428 | -36046, 429 | -50122, 430 | -34789, 431 | 43003, 432 | -78947, 433 | -38763, 434 | -89210, 435 | 32756, 436 | -20389, 437 | -31358, 438 | -90526, 439 | -81607, 440 | 88741, 441 | 86643, 442 | 98422, 443 | 47389, 444 | -75189, 445 | 13091, 446 | 95993, 447 | -15501, 448 | 94260, 449 | -25584, 450 | -1483, 451 | -67261, 452 | -70753, 453 | 25160, 454 | 89614, 455 | -90620, 456 | -48542, 457 | 83889, 458 | -12388, 459 | -9642, 460 | -37043, 461 | -67663, 462 | 28794, 463 | -8801, 464 | 13621, 465 | 12241, 466 | 55379, 467 | 84290, 468 | 21692, 469 | -95906, 470 | -85617, 471 | -17341, 472 | -63767, 473 | 80183, 474 | -4942, 475 | -51478, 476 | 30997, 477 | -13658, 478 | 8838, 479 | 17452, 480 | -82869, 481 | -39897, 482 | 68449, 483 | 31964, 484 | 98158, 485 | -49489, 486 | 62283, 487 | -62209, 488 | -92792, 489 | -59342, 490 | 55146, 491 | -38533, 492 | 20496, 493 | 62667, 494 | 62593, 495 | 36095, 496 | -12470, 497 | 5453, 498 | -50451, 499 | 74716, 500 | -17902, 501 | 3302, 502 | -16760, 503 | -71642, 504 | -34819, 505 | 96459, 506 | -72860, 507 | 21638, 508 | 47342, 509 | -69897, 510 | -40180, 511 | 44466, 512 | 76496, 513 | 84659, 514 | 13848, 515 | -91600, 516 | -90887, 517 | -63742, 518 | -2156, 519 | -84981, 520 | -99280, 521 | 94326, 522 | -33854, 523 | 92029, 524 | -50811, 525 | 98711, 526 | -36459, 527 | -75555, 528 | 79110, 529 | -88164, 530 | -97397, 531 | -84217, 532 | 97457, 533 | 64387, 534 | 30513, 535 | -53190, 536 | -83215, 537 | 252, 538 | 2344, 539 | -27177, 540 | -92945, 541 | -89010, 542 | 82662, 543 | -11670, 544 | 86069, 545 | 53417, 546 | 42702, 547 | 97082, 548 | 3695, 549 | -14530, 550 | -46334, 551 | 17910, 552 | 77999, 553 | 28009, 554 | -12374, 555 | 15498, 556 | -46941, 557 | 97088, 558 | -35030, 559 | 95040, 560 | 92095, 561 | -59469, 562 | -24761, 563 | 46491, 564 | 67357, 565 | -66658, 566 | 37446, 567 | -65130, 568 | -50416, 569 | 99197, 570 | 30925, 571 | 27308, 572 | 54122, 573 | -44719, 574 | 12582, 575 | -99525, 576 | -38446, 577 | -69050, 578 | -22352, 579 | 94757, 580 | -56062, 581 | 33684, 582 | -40199, 583 | -46399, 584 | 96842, 585 | -50881, 586 | -22380, 587 | -65021, 588 | 40582, 589 | 53623, 590 | -76034, 591 | 77018, 592 | -97074, 593 | -84838, 594 | -22953, 595 | -74205, 596 | 79715, 597 | -33920, 598 | -35794, 599 | -91369, 600 | 73421, 601 | -82492, 602 | 63680, 603 | -14915, 604 | -33295, 605 | 37145, 606 | 76852, 607 | -69442, 608 | 60125, 609 | -74166, 610 | 74308, 611 | -1900, 612 | -30195, 613 | -16267, 614 | -60781, 615 | -27760, 616 | 5852, 617 | 38917, 618 | 25742, 619 | -3765, 620 | 49097, 621 | -63541, 622 | 98612, 623 | -92865, 624 | -30248, 625 | 9612, 626 | -8798, 627 | 53262, 628 | 95781, 629 | -42278, 630 | -36529, 631 | 7252, 632 | -27394, 633 | -5021, 634 | 59178, 635 | 80934, 636 | -48480, 637 | -75131, 638 | -54439, 639 | -19145, 640 | -48140, 641 | 98457, 642 | -6601, 643 | -51616, 644 | -89730, 645 | 78028, 646 | 32083, 647 | -48904, 648 | 16822, 649 | -81153, 650 | -8832, 651 | 48720, 652 | -80728, 653 | -45133, 654 | -86647, 655 | -4259, 656 | -40453, 657 | 2590, 658 | 28613, 659 | 50523, 660 | -4105, 661 | -27790, 662 | -74579, 663 | -17223, 664 | 63721, 665 | 33489, 666 | -47921, 667 | 97628, 668 | -97691, 669 | -14782, 670 | -65644, 671 | 18008, 672 | -93651, 673 | -71266, 674 | 80990, 675 | -76732, 676 | -47104, 677 | 35368, 678 | 28632, 679 | 59818, 680 | -86269, 681 | -89753, 682 | 34557, 683 | -92230, 684 | -5933, 685 | -3487, 686 | -73557, 687 | -13174, 688 | -43981, 689 | -43630, 690 | -55171, 691 | 30254, 692 | -83710, 693 | -99583, 694 | -13500, 695 | 71787, 696 | 5017, 697 | -25117, 698 | -78586, 699 | 86941, 700 | -3251, 701 | -23867, 702 | -36315, 703 | 75973, 704 | 86272, 705 | -45575, 706 | 77462, 707 | -98836, 708 | -10859, 709 | 70168, 710 | -32971, 711 | -38739, 712 | -12761, 713 | 93410, 714 | 14014, 715 | -30706, 716 | -77356, 717 | -85965, 718 | -62316, 719 | 63918, 720 | -59914, 721 | -64088, 722 | 1591, 723 | -10957, 724 | 38004, 725 | 15129, 726 | -83602, 727 | -51791, 728 | 34381, 729 | -89382, 730 | -26056, 731 | 8942, 732 | 5465, 733 | 71458, 734 | -73805, 735 | -87445, 736 | -19921, 737 | -80784, 738 | 69150, 739 | -34168, 740 | 28301, 741 | -68955, 742 | 18041, 743 | 6059, 744 | 82342, 745 | 9947, 746 | 39795, 747 | 44047, 748 | -57313, 749 | 48569, 750 | 81936, 751 | -2863, 752 | -80932, 753 | 32976, 754 | -86454, 755 | -84207, 756 | 33033, 757 | 32867, 758 | 9104, 759 | -16580, 760 | -25727, 761 | 80157, 762 | -70169, 763 | 53741, 764 | 86522, 765 | 84651, 766 | 68480, 767 | 84018, 768 | 61932, 769 | 7332, 770 | -61322, 771 | -69663, 772 | 76370, 773 | 41206, 774 | 12326, 775 | -34689, 776 | 17016, 777 | 82975, 778 | -23386, 779 | 39417, 780 | 72793, 781 | 44774, 782 | -96259, 783 | 3213, 784 | 79952, 785 | 29265, 786 | -61492, 787 | -49337, 788 | 14162, 789 | 65886, 790 | 3342, 791 | -41622, 792 | -62659, 793 | -90402, 794 | -24751, 795 | 88511, 796 | 54739, 797 | -21383, 798 | -40161, 799 | -96610, 800 | -24944, 801 | -602, 802 | -76842, 803 | -21856, 804 | 69964, 805 | 43994, 806 | -15121, 807 | -85530, 808 | 12718, 809 | 13170, 810 | -13547, 811 | 69222, 812 | 62417, 813 | -75305, 814 | -81446, 815 | -38786, 816 | -52075, 817 | -23110, 818 | 97681, 819 | -82800, 820 | -53178, 821 | 11474, 822 | 35857, 823 | 94197, 824 | -58148, 825 | -23689, 826 | 32506, 827 | 92154, 828 | -64536, 829 | -73930, 830 | -77138, 831 | 97446, 832 | -83459, 833 | 70963, 834 | 22452, 835 | 68472, 836 | -3728, 837 | -25059, 838 | -49405, 839 | 95129, 840 | -6167, 841 | 12808, 842 | 99918, 843 | 30113, 844 | -12641, 845 | -26665, 846 | 86362, 847 | -33505, 848 | 50661, 849 | 26714, 850 | 33701, 851 | 89012, 852 | -91540, 853 | 40517, 854 | -12716, 855 | -57185, 856 | -87230, 857 | 29914, 858 | -59560, 859 | 13200, 860 | -72723, 861 | 58272, 862 | 23913, 863 | -45586, 864 | -96593, 865 | -26265, 866 | -2141, 867 | 31087, 868 | 81399, 869 | 92511, 870 | -34049, 871 | 20577, 872 | 2803, 873 | 26003, 874 | 8940, 875 | 42117, 876 | 40887, 877 | -82715, 878 | 38269, 879 | 40969, 880 | -50022, 881 | 72088, 882 | 21291, 883 | -67280, 884 | -16523, 885 | 90535, 886 | 18669, 887 | 94342, 888 | -39568, 889 | -88080, 890 | -99486, 891 | -20716, 892 | 23108, 893 | -28037, 894 | 63342, 895 | 36863, 896 | -29420, 897 | -44016, 898 | 75135, 899 | 73415, 900 | 16059, 901 | -4899, 902 | 86893, 903 | 43136, 904 | -7041, 905 | 33483, 906 | -67612, 907 | 25327, 908 | 40830, 909 | 6184, 910 | 61805, 911 | 4247, 912 | 81119, 913 | -22854, 914 | -26104, 915 | -63466, 916 | 63093, 917 | -63685, 918 | 60369, 919 | 51023, 920 | 51644, 921 | -16350, 922 | 74438, 923 | -83514, 924 | 99083, 925 | 10079, 926 | -58451, 927 | -79621, 928 | 48471, 929 | 67131, 930 | -86940, 931 | 99093, 932 | 11855, 933 | -22272, 934 | -67683, 935 | -44371, 936 | 9541, 937 | 18123, 938 | 37766, 939 | -70922, 940 | 80385, 941 | -57513, 942 | -76021, 943 | -47890, 944 | 36154, 945 | 72935, 946 | 84387, 947 | -92681, 948 | -88303, 949 | -7810, 950 | 59902, 951 | -90, 952 | -64704, 953 | -28396, 954 | -66403, 955 | 8860, 956 | 13343, 957 | 33882, 958 | 85680, 959 | 7228, 960 | 28160, 961 | -14003, 962 | 54369, 963 | -58893, 964 | 92606, 965 | -63492, 966 | -10101, 967 | 64714, 968 | 58486, 969 | 29948, 970 | -44679, 971 | -22763, 972 | 10151, 973 | -56695, 974 | 4031, 975 | -18242, 976 | -36232, 977 | 86168, 978 | -14263, 979 | 9883, 980 | 47124, 981 | 47271, 982 | 92761, 983 | -24958, 984 | -73263, 985 | -79661, 986 | -69147, 987 | -18874, 988 | 29546, 989 | -92588, 990 | -85771, 991 | 26451, 992 | -86650, 993 | -43306, 994 | -59094, 995 | -47492, 996 | -34821, 997 | -91763, 998 | -47670, 999 | 33537, 1000 | 22843, 1001 | 67417, 1002 | -759, 1003 | 92159, 1004 | 63075, 1005 | 94065, 1006 | -26988, 1007 | 55276, 1008 | 65903, 1009 | 30414, 1010 | -67129, 1011 | -99508, 1012 | -83092, 1013 | -91493, 1014 | -50426, 1015 | 14349, 1016 | -83216, 1017 | -76090, 1018 | 32742, 1019 | -5306, 1020 | -93310, 1021 | -60750, 1022 | -60620, 1023 | -45484, 1024 | -21108, 1025 | -58341, 1026 | -28048, 1027 | -52803, 1028 | 69735, 1029 | 78906, 1030 | 81649, 1031 | 32565, 1032 | -86804, 1033 | -83202, 1034 | -65688, 1035 | -1760, 1036 | 89707, 1037 | 93322, 1038 | -72750, 1039 | 84134, 1040 | 71900, 1041 | -37720, 1042 | 19450, 1043 | -78018, 1044 | 22001, 1045 | -23604, 1046 | 26276, 1047 | -21498, 1048 | 65892, 1049 | -72117, 1050 | -89834, 1051 | -23867, 1052 | 55817, 1053 | -77963, 1054 | 42518, 1055 | 93123, 1056 | -83916, 1057 | 63260, 1058 | -2243, 1059 | -97108, 1060 | 85442, 1061 | -36775, 1062 | 17984, 1063 | -58810, 1064 | 99664, 1065 | -19082, 1066 | 93075, 1067 | -69329, 1068 | 87061, 1069 | 79713, 1070 | 16296, 1071 | 70996, 1072 | 13483, 1073 | -74582, 1074 | 49900, 1075 | -27669, 1076 | -40562, 1077 | 1209, 1078 | -20572, 1079 | 34660, 1080 | 83193, 1081 | 75579, 1082 | 7344, 1083 | 64925, 1084 | 88361, 1085 | 60969, 1086 | 3114, 1087 | 44611, 1088 | -27445, 1089 | 53049, 1090 | -16085, 1091 | -92851, 1092 | -53306, 1093 | 13859, 1094 | -33532, 1095 | 86622, 1096 | -75666, 1097 | -18159, 1098 | -98256, 1099 | 51875, 1100 | -42251, 1101 | -27977, 1102 | -18080, 1103 | 23772, 1104 | 38160, 1105 | 41779, 1106 | 9147, 1107 | 94175, 1108 | 99905, 1109 | -85755, 1110 | 62535, 1111 | -88412, 1112 | -52038, 1113 | -68171, 1114 | 93255, 1115 | -44684, 1116 | -11242, 1117 | -104, 1118 | 31796, 1119 | 62346, 1120 | -54931, 1121 | -55790, 1122 | -70032, 1123 | 46221, 1124 | 56541, 1125 | -91947, 1126 | 90592, 1127 | 93503, 1128 | 4071, 1129 | 20646, 1130 | 4856, 1131 | -63598, 1132 | 15396, 1133 | -50708, 1134 | 32138, 1135 | -85164, 1136 | 38528, 1137 | -89959, 1138 | 53852, 1139 | 57915, 1140 | -42421, 1141 | -88916, 1142 | -75072, 1143 | 67030, 1144 | -29066, 1145 | 49542, 1146 | -71591, 1147 | 61708, 1148 | -53985, 1149 | -43051, 1150 | 28483, 1151 | 46991, 1152 | -83216, 1153 | 80991, 1154 | -46254, 1155 | -48716, 1156 | 39356, 1157 | -8270, 1158 | -47763, 1159 | -34410, 1160 | 874, 1161 | -1186, 1162 | -7049, 1163 | 28846, 1164 | 11276, 1165 | 21960, 1166 | -13304, 1167 | -11433, 1168 | -4913, 1169 | 55754, 1170 | 79616, 1171 | 70423, 1172 | -27523, 1173 | 64803, 1174 | 49277, 1175 | 14906, 1176 | -97401, 1177 | -92390, 1178 | 91075, 1179 | 70736, 1180 | 21971, 1181 | -3303, 1182 | 55333, 1183 | -93996, 1184 | 76538, 1185 | 54603, 1186 | -75899, 1187 | 98801, 1188 | 46887, 1189 | 35041, 1190 | 48302, 1191 | -52318, 1192 | 55439, 1193 | 24574, 1194 | 14079, 1195 | -24889, 1196 | 83440, 1197 | 14961, 1198 | 34312, 1199 | -89260, 1200 | -22293, 1201 | -81271, 1202 | -2586, 1203 | -71059, 1204 | -10640, 1205 | -93095, 1206 | -5453, 1207 | -70041, 1208 | 66543, 1209 | 74012, 1210 | -11662, 1211 | -52477, 1212 | -37597, 1213 | -70919, 1214 | 92971, 1215 | -17452, 1216 | -67306, 1217 | -80418, 1218 | 7225, 1219 | -89296, 1220 | 24296, 1221 | 86547, 1222 | 37154, 1223 | -10696, 1224 | 74436, 1225 | -63959, 1226 | 58860, 1227 | 33590, 1228 | -88925, 1229 | -97814, 1230 | -83664, 1231 | 85484, 1232 | -8385, 1233 | -50879, 1234 | 57729, 1235 | -74728, 1236 | -87852, 1237 | -15524, 1238 | -91120, 1239 | 22062, 1240 | 28134, 1241 | 80917, 1242 | 32026, 1243 | 49707, 1244 | -54252, 1245 | -44319, 1246 | -35139, 1247 | 13777, 1248 | 44660, 1249 | 85274, 1250 | 25043, 1251 | 58781, 1252 | -89035, 1253 | -76274, 1254 | 6364, 1255 | -63625, 1256 | 72855, 1257 | 43242, 1258 | -35033, 1259 | 12820, 1260 | -27460, 1261 | 77372, 1262 | -47578, 1263 | -61162, 1264 | -70758, 1265 | -1343, 1266 | -4159, 1267 | 64935, 1268 | 56024, 1269 | -2151, 1270 | 43770, 1271 | 19758, 1272 | -30186, 1273 | -86040, 1274 | 24666, 1275 | -62332, 1276 | -67542, 1277 | 73180, 1278 | -25821, 1279 | -27826, 1280 | -45504, 1281 | -36858, 1282 | -12041, 1283 | 20017, 1284 | -24066, 1285 | -56625, 1286 | -52097, 1287 | -47239, 1288 | -90694, 1289 | 8959, 1290 | 7712, 1291 | -14258, 1292 | -5860, 1293 | 55349, 1294 | 61808, 1295 | -4423, 1296 | -93703, 1297 | 64681, 1298 | -98641, 1299 | -25222, 1300 | 46999, 1301 | -83831, 1302 | -54714, 1303 | 19997, 1304 | -68477, 1305 | 66073, 1306 | 51801, 1307 | -66491, 1308 | 52061, 1309 | -52866, 1310 | 79907, 1311 | -39736, 1312 | -68331, 1313 | 68937, 1314 | 91464, 1315 | 98892, 1316 | 910, 1317 | 93501, 1318 | 31295, 1319 | -85873, 1320 | 27036, 1321 | -57340, 1322 | 50412, 1323 | 21, 1324 | -2445, 1325 | 29471, 1326 | 71317, 1327 | 82093, 1328 | -94823, 1329 | -54458, 1330 | -97410, 1331 | 39560, 1332 | -7628, 1333 | 66452, 1334 | 39701, 1335 | 54029, 1336 | 37906, 1337 | 46773, 1338 | 58296, 1339 | 60370, 1340 | -61090, 1341 | 85501, 1342 | -86874, 1343 | 71443, 1344 | -72702, 1345 | -72047, 1346 | 14848, 1347 | 34102, 1348 | 77975, 1349 | -66294, 1350 | -36576, 1351 | 31349, 1352 | 52493, 1353 | -70833, 1354 | -80287, 1355 | 94435, 1356 | 39745, 1357 | -98291, 1358 | 84524, 1359 | -18942, 1360 | 10236, 1361 | 93448, 1362 | 50846, 1363 | 94023, 1364 | -6939, 1365 | 47999, 1366 | 14740, 1367 | 30165, 1368 | 81048, 1369 | 84935, 1370 | -19177, 1371 | -13594, 1372 | 32289, 1373 | 62628, 1374 | -90612, 1375 | -542, 1376 | -66627, 1377 | 64255, 1378 | 71199, 1379 | -83841, 1380 | -82943, 1381 | -73885, 1382 | 8623, 1383 | -67214, 1384 | -9474, 1385 | -35249, 1386 | 62254, 1387 | -14087, 1388 | -90969, 1389 | 21515, 1390 | -83303, 1391 | 94377, 1392 | -91619, 1393 | 19956, 1394 | -98810, 1395 | 96727, 1396 | -91939, 1397 | 29119, 1398 | -85473, 1399 | -82153, 1400 | -69008, 1401 | 44850, 1402 | 74299, 1403 | -76459, 1404 | -86464, 1405 | 8315, 1406 | -49912, 1407 | -28665, 1408 | 59052, 1409 | -69708, 1410 | 76024, 1411 | -92738, 1412 | 50098, 1413 | 18683, 1414 | -91438, 1415 | 18096, 1416 | -19335, 1417 | 35659, 1418 | 91826, 1419 | 15779, 1420 | -73070, 1421 | 67873, 1422 | -12458, 1423 | -71440, 1424 | -46721, 1425 | 54856, 1426 | 97212, 1427 | -81875, 1428 | 35805, 1429 | 36952, 1430 | 68498, 1431 | 81627, 1432 | -34231, 1433 | 81712, 1434 | 27100, 1435 | -9741, 1436 | -82612, 1437 | 18766, 1438 | -36392, 1439 | 2759, 1440 | 41728, 1441 | 69743, 1442 | 26825, 1443 | 48355, 1444 | -17790, 1445 | 17165, 1446 | 56558, 1447 | 3295, 1448 | -24375, 1449 | 55669, 1450 | -16109, 1451 | 24079, 1452 | 73414, 1453 | 48990, 1454 | -11931, 1455 | -78214, 1456 | 90745, 1457 | 19878, 1458 | 35673, 1459 | -15317, 1460 | -89086, 1461 | 94675, 1462 | -92513, 1463 | 88410, 1464 | -93248, 1465 | -19475, 1466 | -74041, 1467 | -19165, 1468 | 32329, 1469 | -26266, 1470 | -46828, 1471 | -18747, 1472 | 45328, 1473 | 8990, 1474 | -78219, 1475 | -25874, 1476 | -74801, 1477 | -44956, 1478 | -54577, 1479 | -29756, 1480 | -99822, 1481 | -35731, 1482 | -18348, 1483 | -68915, 1484 | -83518, 1485 | -53451, 1486 | 95471, 1487 | -2954, 1488 | -13706, 1489 | -8763, 1490 | -21642, 1491 | -37210, 1492 | 16814, 1493 | -60070, 1494 | -42743, 1495 | 27697, 1496 | -36333, 1497 | -42362, 1498 | 11576, 1499 | 85742, 1500 | -82536, 1501 | 68767, 1502 | -56103, 1503 | -63012, 1504 | 71396, 1505 | -78464, 1506 | -68101, 1507 | -15917, 1508 | -11113, 1509 | -3596, 1510 | 77626, 1511 | -60191, 1512 | -30585, 1513 | -73584, 1514 | 6214, 1515 | -84303, 1516 | 18403, 1517 | 23618, 1518 | -15619, 1519 | -89755, 1520 | -59515, 1521 | -59103, 1522 | -74308, 1523 | -63725, 1524 | -29364, 1525 | -52376, 1526 | -96130, 1527 | 70894, 1528 | -12609, 1529 | 50845, 1530 | -2314, 1531 | 42264, 1532 | -70825, 1533 | 64481, 1534 | 55752, 1535 | 4460, 1536 | -68603, 1537 | -88701, 1538 | 4713, 1539 | -50441, 1540 | -51333, 1541 | -77907, 1542 | 97412, 1543 | -66616, 1544 | -49430, 1545 | 60489, 1546 | -85262, 1547 | -97621, 1548 | -18980, 1549 | 44727, 1550 | -69321, 1551 | -57730, 1552 | 66287, 1553 | -92566, 1554 | -64427, 1555 | -14270, 1556 | 11515, 1557 | -92612, 1558 | -87645, 1559 | 61557, 1560 | 24197, 1561 | -81923, 1562 | -39831, 1563 | -10301, 1564 | -23640, 1565 | -76219, 1566 | -68025, 1567 | 92761, 1568 | -76493, 1569 | 68554, 1570 | -77734, 1571 | -95620, 1572 | -11753, 1573 | -51700, 1574 | 98234, 1575 | -68544, 1576 | -61838, 1577 | 29467, 1578 | 46603, 1579 | -18221, 1580 | -35441, 1581 | 74537, 1582 | 40327, 1583 | -58293, 1584 | 75755, 1585 | -57301, 1586 | -7532, 1587 | -94163, 1588 | 18179, 1589 | -14388, 1590 | -22258, 1591 | -46417, 1592 | -48285, 1593 | 18242, 1594 | -77551, 1595 | 82620, 1596 | 250, 1597 | -20060, 1598 | -79568, 1599 | -77259, 1600 | 82052, 1601 | -98897, 1602 | -75464, 1603 | 48773, 1604 | -79040, 1605 | -11293, 1606 | 45941, 1607 | -67876, 1608 | -69204, 1609 | -46477, 1610 | -46107, 1611 | 792, 1612 | 60546, 1613 | -34573, 1614 | -12879, 1615 | -94562, 1616 | 20356, 1617 | -48004, 1618 | -62429, 1619 | 96242, 1620 | 40594, 1621 | 2099, 1622 | 99494, 1623 | 25724, 1624 | -39394, 1625 | -2388, 1626 | -18563, 1627 | -56510, 1628 | -83570, 1629 | -29214, 1630 | 3015, 1631 | 74454, 1632 | 74197, 1633 | 76678, 1634 | -46597, 1635 | 60630, 1636 | -76093, 1637 | 37578, 1638 | -82045, 1639 | -24077, 1640 | 62082, 1641 | -87787, 1642 | -74936, 1643 | 58687, 1644 | 12200, 1645 | -98952, 1646 | 70155, 1647 | -77370, 1648 | 21710, 1649 | -84625, 1650 | -60556, 1651 | -84128, 1652 | 925, 1653 | 65474, 1654 | -15741, 1655 | -94619, 1656 | 88377, 1657 | 89334, 1658 | 44749, 1659 | 22002, 1660 | -45750, 1661 | -93081, 1662 | -14600, 1663 | -83447, 1664 | 46691, 1665 | 85040, 1666 | -66447, 1667 | -80085, 1668 | 56308, 1669 | 44310, 1670 | 24979, 1671 | -29694, 1672 | 57991, 1673 | 4675, 1674 | -71273, 1675 | -44508, 1676 | 13615, 1677 | -54710, 1678 | 23552, 1679 | -78253, 1680 | -34637, 1681 | 50497, 1682 | 68706, 1683 | 81543, 1684 | -88408, 1685 | -21405, 1686 | 6001, 1687 | -33834, 1688 | -21570, 1689 | -46692, 1690 | -25344, 1691 | 20310, 1692 | 71258, 1693 | -97680, 1694 | 11721, 1695 | 59977, 1696 | 59247, 1697 | -48949, 1698 | 98955, 1699 | -50276, 1700 | -80844, 1701 | -27935, 1702 | -76102, 1703 | 55858, 1704 | -33492, 1705 | 40680, 1706 | 66691, 1707 | -33188, 1708 | 8284, 1709 | 64893, 1710 | -7528, 1711 | 6019, 1712 | -85523, 1713 | 8434, 1714 | -64366, 1715 | -56663, 1716 | 26862, 1717 | 30008, 1718 | -7611, 1719 | -12179, 1720 | -70076, 1721 | 21426, 1722 | -11261, 1723 | -36864, 1724 | -61937, 1725 | -59677, 1726 | 929, 1727 | -21052, 1728 | 3848, 1729 | -20888, 1730 | -16065, 1731 | 98995, 1732 | -32293, 1733 | -86121, 1734 | -54564, 1735 | 77831, 1736 | 68602, 1737 | 74977, 1738 | 31658, 1739 | 40699, 1740 | 29755, 1741 | 98424, 1742 | 80358, 1743 | -69337, 1744 | 26339, 1745 | 13213, 1746 | -46016, 1747 | -18331, 1748 | 64713, 1749 | -46883, 1750 | -58451, 1751 | -70024, 1752 | -92393, 1753 | -4088, 1754 | 70628, 1755 | -51185, 1756 | 71164, 1757 | -75791, 1758 | -1636, 1759 | -29102, 1760 | -16929, 1761 | -87650, 1762 | -84589, 1763 | -24229, 1764 | -42137, 1765 | -15653, 1766 | 94825, 1767 | 13042, 1768 | 88499, 1769 | -47100, 1770 | -90358, 1771 | -7180, 1772 | 29754, 1773 | -65727, 1774 | -42659, 1775 | -85560, 1776 | -9037, 1777 | -52459, 1778 | 20997, 1779 | -47425, 1780 | 17318, 1781 | 21122, 1782 | 20472, 1783 | -23037, 1784 | 65216, 1785 | -63625, 1786 | -7877, 1787 | -91907, 1788 | 24100, 1789 | -72516, 1790 | 22903, 1791 | -85247, 1792 | -8938, 1793 | 73878, 1794 | 54953, 1795 | 87480, 1796 | -31466, 1797 | -99524, 1798 | 35369, 1799 | -78376, 1800 | 89984, 1801 | -15982, 1802 | 94045, 1803 | -7269, 1804 | 23319, 1805 | -80456, 1806 | -37653, 1807 | -76756, 1808 | 2909, 1809 | 81936, 1810 | 54958, 1811 | -12393, 1812 | 60560, 1813 | -84664, 1814 | -82413, 1815 | 66941, 1816 | -26573, 1817 | -97532, 1818 | 64460, 1819 | 18593, 1820 | -85789, 1821 | -38820, 1822 | -92575, 1823 | -43663, 1824 | -89435, 1825 | 83272, 1826 | -50585, 1827 | 13616, 1828 | -71541, 1829 | -53156, 1830 | 727, 1831 | -27644, 1832 | 16538, 1833 | 34049, 1834 | 57745, 1835 | 34348, 1836 | 35009, 1837 | 16634, 1838 | -18791, 1839 | 23271, 1840 | -63844, 1841 | 95817, 1842 | 21781, 1843 | 16590, 1844 | 59669, 1845 | 15966, 1846 | -6864, 1847 | 48050, 1848 | -36143, 1849 | 97427, 1850 | -59390, 1851 | 96931, 1852 | 78939, 1853 | -1958, 1854 | 50777, 1855 | 43338, 1856 | -51149, 1857 | 39235, 1858 | -27054, 1859 | -43492, 1860 | 67457, 1861 | -83616, 1862 | 37179, 1863 | 10390, 1864 | 85818, 1865 | 2391, 1866 | 73635, 1867 | 87579, 1868 | -49127, 1869 | -81264, 1870 | -79023, 1871 | -81590, 1872 | 53554, 1873 | -74972, 1874 | -83940, 1875 | -13726, 1876 | -39095, 1877 | 29174, 1878 | 78072, 1879 | 76104, 1880 | 47778, 1881 | 25797, 1882 | -29515, 1883 | -6493, 1884 | -92793, 1885 | 22481, 1886 | -36197, 1887 | -65560, 1888 | 42342, 1889 | 15750, 1890 | 97556, 1891 | 99634, 1892 | -56048, 1893 | -35688, 1894 | 13501, 1895 | 63969, 1896 | -74291, 1897 | 50911, 1898 | 39225, 1899 | 93702, 1900 | -3490, 1901 | -59461, 1902 | -30105, 1903 | -46761, 1904 | -80113, 1905 | 92906, 1906 | -68487, 1907 | 50742, 1908 | 36152, 1909 | -90240, 1910 | -83631, 1911 | 24597, 1912 | -50566, 1913 | -15477, 1914 | 18470, 1915 | 77038, 1916 | 40223, 1917 | -80364, 1918 | -98676, 1919 | 70957, 1920 | -63647, 1921 | 99537, 1922 | 13041, 1923 | 31679, 1924 | 86631, 1925 | 37633, 1926 | -16866, 1927 | 13686, 1928 | -71565, 1929 | 21652, 1930 | -46053, 1931 | -80578, 1932 | -61382, 1933 | 68487, 1934 | -6417, 1935 | 4656, 1936 | 20811, 1937 | 67013, 1938 | -30868, 1939 | -11219, 1940 | 46, 1941 | 74944, 1942 | 14627, 1943 | 56965, 1944 | 42275, 1945 | -52480, 1946 | 52162, 1947 | -84883, 1948 | -52579, 1949 | -90331, 1950 | 92792, 1951 | 42184, 1952 | -73422, 1953 | -58440, 1954 | 65308, 1955 | -25069, 1956 | 5475, 1957 | -57996, 1958 | 59557, 1959 | -17561, 1960 | 2826, 1961 | -56939, 1962 | 14996, 1963 | -94855, 1964 | -53707, 1965 | 99159, 1966 | 43645, 1967 | -67719, 1968 | -1331, 1969 | 21412, 1970 | 41704, 1971 | 31612, 1972 | 32622, 1973 | 1919, 1974 | -69333, 1975 | -69828, 1976 | 22422, 1977 | -78842, 1978 | 57896, 1979 | -17363, 1980 | 27979, 1981 | -76897, 1982 | 35008, 1983 | 46482, 1984 | -75289, 1985 | 65799, 1986 | 20057, 1987 | 7170, 1988 | 41326, 1989 | -76069, 1990 | 90840, 1991 | -81253, 1992 | -50749, 1993 | 3649, 1994 | -42315, 1995 | 45238, 1996 | -33924, 1997 | 62101, 1998 | 96906, 1999 | 58884, 2000 | -7617, 2001 | -28689, 2002 | -66578, 2003 | 62458, 2004 | 50876, 2005 | -57553, 2006 | 6739, 2007 | 41014, 2008 | -64040, 2009 | -34916, 2010 | 37940, 2011 | 13048, 2012 | -97478, 2013 | -11318, 2014 | -89440, 2015 | -31933, 2016 | -40357, 2017 | -59737, 2018 | -76718, 2019 | -14104, 2020 | -31774, 2021 | 28001, 2022 | 4103, 2023 | 41702, 2024 | -25120, 2025 | -31654, 2026 | 63085, 2027 | -3642, 2028 | 84870, 2029 | -83896, 2030 | -76422, 2031 | -61520, 2032 | 12900, 2033 | 88678, 2034 | 85547, 2035 | 33132, 2036 | -88627, 2037 | 52820, 2038 | 63915, 2039 | -27472, 2040 | 78867, 2041 | -51439, 2042 | 33005, 2043 | -23447, 2044 | -3271, 2045 | -39308, 2046 | 39726, 2047 | -74260, 2048 | -31874, 2049 | -36893, 2050 | 93656, 2051 | 910, 2052 | -98362, 2053 | 60450, 2054 | -88048, 2055 | 99308, 2056 | 13947, 2057 | 83996, 2058 | -90415, 2059 | -35117, 2060 | 70858, 2061 | -55332, 2062 | -31721, 2063 | 97528, 2064 | 82982, 2065 | -86218, 2066 | 6822, 2067 | 25227, 2068 | 36946, 2069 | 97077, 2070 | -4257, 2071 | -41526, 2072 | 56795, 2073 | 89870, 2074 | 75860, 2075 | -70802, 2076 | 21779, 2077 | 14184, 2078 | -16511, 2079 | -89156, 2080 | -31422, 2081 | 71470, 2082 | 69600, 2083 | -78498, 2084 | 74079, 2085 | -19410, 2086 | 40311, 2087 | 28501, 2088 | 26397, 2089 | -67574, 2090 | -32518, 2091 | 68510, 2092 | 38615, 2093 | 19355, 2094 | -6088, 2095 | -97159, 2096 | -29255, 2097 | -92523, 2098 | 3023, 2099 | -42536, 2100 | -88681, 2101 | 64255, 2102 | 41206, 2103 | 44119, 2104 | 52208, 2105 | 39522, 2106 | -52108, 2107 | 91276, 2108 | -70514, 2109 | 83436, 2110 | 63289, 2111 | -79741, 2112 | 9623, 2113 | 99559, 2114 | 12642, 2115 | 85950, 2116 | 83735, 2117 | -21156, 2118 | -67208, 2119 | 98088, 2120 | -7341, 2121 | -27763, 2122 | -30048, 2123 | -44099, 2124 | -14866, 2125 | -45504, 2126 | -91704, 2127 | 19369, 2128 | 13700, 2129 | 10481, 2130 | -49344, 2131 | -85686, 2132 | 33994, 2133 | 19672, 2134 | 36028, 2135 | 60842, 2136 | 66564, 2137 | -24919, 2138 | 33950, 2139 | -93616, 2140 | -47430, 2141 | -35391, 2142 | -28279, 2143 | 56806, 2144 | 74690, 2145 | 39284, 2146 | -96683, 2147 | -7642, 2148 | -75232, 2149 | 37657, 2150 | -14531, 2151 | -86870, 2152 | -9274, 2153 | -26173, 2154 | 98640, 2155 | 88652, 2156 | 64257, 2157 | 46457, 2158 | 37814, 2159 | -19370, 2160 | 9337, 2161 | -22556, 2162 | -41525, 2163 | 39105, 2164 | -28719, 2165 | 51611, 2166 | -93252, 2167 | 98044, 2168 | -90996, 2169 | 21710, 2170 | -47605, 2171 | -64259, 2172 | -32727, 2173 | 53611, 2174 | -31918, 2175 | -3555, 2176 | 33316, 2177 | -66472, 2178 | 21274, 2179 | -37731, 2180 | -2919, 2181 | 15016, 2182 | 48779, 2183 | -88868, 2184 | 1897, 2185 | 41728, 2186 | 46344, 2187 | -89667, 2188 | 37848, 2189 | 68092, 2190 | -44011, 2191 | 85354, 2192 | -43776, 2193 | 38739, 2194 | -31423, 2195 | -66330, 2196 | 65167, 2197 | -22016, 2198 | 59405, 2199 | 34328, 2200 | -60042, 2201 | 87660, 2202 | -67698, 2203 | -59174, 2204 | -1408, 2205 | -46809, 2206 | -43485, 2207 | -88807, 2208 | -60489, 2209 | 13974, 2210 | 22319, 2211 | 55836, 2212 | -62995, 2213 | -37375, 2214 | -4185, 2215 | 32687, 2216 | -36551, 2217 | -75237, 2218 | 58280, 2219 | 26942, 2220 | -73756, 2221 | 71756, 2222 | 78775, 2223 | -40573, 2224 | 14367, 2225 | -71622, 2226 | -77338, 2227 | 24112, 2228 | 23414, 2229 | -7679, 2230 | -51721, 2231 | 87492, 2232 | 85066, 2233 | -21612, 2234 | 57045, 2235 | 10673, 2236 | -96836, 2237 | 52461, 2238 | -62218, 2239 | -9310, 2240 | 65862, 2241 | -22748, 2242 | 89906, 2243 | -96987, 2244 | -98698, 2245 | 26956, 2246 | -43428, 2247 | 46141, 2248 | 47456, 2249 | 28095, 2250 | 55952, 2251 | 67323, 2252 | -36455, 2253 | -60202, 2254 | -43302, 2255 | -82932, 2256 | 42020, 2257 | 77036, 2258 | 10142, 2259 | 60406, 2260 | 70331, 2261 | 63836, 2262 | 58850, 2263 | -66752, 2264 | 52109, 2265 | 21395, 2266 | -10238, 2267 | -98647, 2268 | -41962, 2269 | 27778, 2270 | 69060, 2271 | 98535, 2272 | -28680, 2273 | -52263, 2274 | -56679, 2275 | 66103, 2276 | -42426, 2277 | 27203, 2278 | 80021, 2279 | 10153, 2280 | 58678, 2281 | 36398, 2282 | 63112, 2283 | 34911, 2284 | 20515, 2285 | 62082, 2286 | -15659, 2287 | -40785, 2288 | 27054, 2289 | 43767, 2290 | -20289, 2291 | 65838, 2292 | -6954, 2293 | -60228, 2294 | -72226, 2295 | 52236, 2296 | -35464, 2297 | 25209, 2298 | -15462, 2299 | -79617, 2300 | -41668, 2301 | -84083, 2302 | 62404, 2303 | -69062, 2304 | 18913, 2305 | 46545, 2306 | 20757, 2307 | 13805, 2308 | 24717, 2309 | -18461, 2310 | -47009, 2311 | -25779, 2312 | 68834, 2313 | 64824, 2314 | 34473, 2315 | 39576, 2316 | 31570, 2317 | 14861, 2318 | -15114, 2319 | -41233, 2320 | 95509, 2321 | 68232, 2322 | 67846, 2323 | 84902, 2324 | -83060, 2325 | 17642, 2326 | -18422, 2327 | 73688, 2328 | 77671, 2329 | -26930, 2330 | 64484, 2331 | -99637, 2332 | 73875, 2333 | 6428, 2334 | 21034, 2335 | -73471, 2336 | 19664, 2337 | -68031, 2338 | 15922, 2339 | -27028, 2340 | 48137, 2341 | 54955, 2342 | -82793, 2343 | -41144, 2344 | -10218, 2345 | -24921, 2346 | -28299, 2347 | -2288, 2348 | 68518, 2349 | -54452, 2350 | 15686, 2351 | -41814, 2352 | 66165, 2353 | -72207, 2354 | -61986, 2355 | 80020, 2356 | 50544, 2357 | -99500, 2358 | 16244, 2359 | 78998, 2360 | 40989, 2361 | 14525, 2362 | -56061, 2363 | -24692, 2364 | -94790, 2365 | 21111, 2366 | 37296, 2367 | -90794, 2368 | 72100, 2369 | 70550, 2370 | -31757, 2371 | 17708, 2372 | -74290, 2373 | 61910, 2374 | 78039, 2375 | -78629, 2376 | -25033, 2377 | 73172, 2378 | -91953, 2379 | 10052, 2380 | 64502, 2381 | 99585, 2382 | -1741, 2383 | 90324, 2384 | -73723, 2385 | 68942, 2386 | 28149, 2387 | 30218, 2388 | 24422, 2389 | 16659, 2390 | 10710, 2391 | -62594, 2392 | 94249, 2393 | 96588, 2394 | 46192, 2395 | 34251, 2396 | 73500, 2397 | -65995, 2398 | -81168, 2399 | 41412, 2400 | -98724, 2401 | -63710, 2402 | -54696, 2403 | -52407, 2404 | 19746, 2405 | 45869, 2406 | 27821, 2407 | -94866, 2408 | -76705, 2409 | -13417, 2410 | -61995, 2411 | -71560, 2412 | 43450, 2413 | 67384, 2414 | -8838, 2415 | -80293, 2416 | -28937, 2417 | 23330, 2418 | -89694, 2419 | -40586, 2420 | 46918, 2421 | 80429, 2422 | -5475, 2423 | 78013, 2424 | 25309, 2425 | -34162, 2426 | 37236, 2427 | -77577, 2428 | 86744, 2429 | 26281, 2430 | -29033, 2431 | -91813, 2432 | 35347, 2433 | 13033, 2434 | -13631, 2435 | -24459, 2436 | 3325, 2437 | -71078, 2438 | -75359, 2439 | 81311, 2440 | 19700, 2441 | 47678, 2442 | -74680, 2443 | -84113, 2444 | 45192, 2445 | 35502, 2446 | 37675, 2447 | 19553, 2448 | 76522, 2449 | -51098, 2450 | -18211, 2451 | 89717, 2452 | 4508, 2453 | -82946, 2454 | 27749, 2455 | 85995, 2456 | 89912, 2457 | -53678, 2458 | -64727, 2459 | -14778, 2460 | 32075, 2461 | -63412, 2462 | -40524, 2463 | 86440, 2464 | -2707, 2465 | -36821, 2466 | 63850, 2467 | -30883, 2468 | 67294, 2469 | -99468, 2470 | -23708, 2471 | 34932, 2472 | 34386, 2473 | 98899, 2474 | 29239, 2475 | -23385, 2476 | 5897, 2477 | 54882, 2478 | 98660, 2479 | 49098, 2480 | 70275, 2481 | 17718, 2482 | 88533, 2483 | 52161, 2484 | 63340, 2485 | 50061, 2486 | -89457, 2487 | 19491, 2488 | -99156, 2489 | 24873, 2490 | -17008, 2491 | 64610, 2492 | -55543, 2493 | 50495, 2494 | 17056, 2495 | -10400, 2496 | -56678, 2497 | -29073, 2498 | -42960, 2499 | -76418, 2500 | 98562, 2501 | -88104, 2502 | -96255, 2503 | 10159, 2504 | -90724, 2505 | 54011, 2506 | 12052, 2507 | 45871, 2508 | -90933, 2509 | -69420, 2510 | 67039, 2511 | 37202, 2512 | 78051, 2513 | -52197, 2514 | -40278, 2515 | -58425, 2516 | 65414, 2517 | -23394, 2518 | -1415, 2519 | 6912, 2520 | -53447, 2521 | 7352, 2522 | 17307, 2523 | -78147, 2524 | 63727, 2525 | 98905, 2526 | 55412, 2527 | -57658, 2528 | -32884, 2529 | -44878, 2530 | 22755, 2531 | 39730, 2532 | 3638, 2533 | 35111, 2534 | 39777, 2535 | 74193, 2536 | 38736, 2537 | -11829, 2538 | -61188, 2539 | -92757, 2540 | 55946, 2541 | -71232, 2542 | -63032, 2543 | -83947, 2544 | 39147, 2545 | -96684, 2546 | -99233, 2547 | 25131, 2548 | -32197, 2549 | 24406, 2550 | -55428, 2551 | -61941, 2552 | 25874, 2553 | -69453, 2554 | 64483, 2555 | -19644, 2556 | -68441, 2557 | 12783, 2558 | 87338, 2559 | -48676, 2560 | 66451, 2561 | -447, 2562 | -61590, 2563 | 50932, 2564 | -11270, 2565 | 29035, 2566 | 65698, 2567 | -63544, 2568 | 10029, 2569 | 80499, 2570 | -9461, 2571 | 86368, 2572 | 91365, 2573 | -81810, 2574 | -71914, 2575 | -52056, 2576 | -13782, 2577 | 44240, 2578 | -30093, 2579 | -2437, 2580 | 24007, 2581 | 67581, 2582 | -17365, 2583 | -69164, 2584 | -8420, 2585 | -69289, 2586 | -29370, 2587 | 48010, 2588 | 90439, 2589 | 13141, 2590 | 69243, 2591 | 50668, 2592 | 39328, 2593 | 61731, 2594 | 78266, 2595 | -81313, 2596 | 17921, 2597 | -38196, 2598 | 55261, 2599 | 9948, 2600 | -24970, 2601 | 75712, 2602 | -72106, 2603 | 28696, 2604 | 7461, 2605 | 31621, 2606 | 61047, 2607 | 51476, 2608 | 56512, 2609 | 11839, 2610 | -96916, 2611 | -82739, 2612 | 28924, 2613 | -99927, 2614 | 58449, 2615 | 37280, 2616 | 69357, 2617 | 11219, 2618 | -32119, 2619 | -62050, 2620 | -48745, 2621 | -83486, 2622 | -52376, 2623 | 42668, 2624 | 82659, 2625 | 68882, 2626 | 38773, 2627 | 46269, 2628 | -96005, 2629 | 97630, 2630 | 25009, 2631 | -2951, 2632 | -67811, 2633 | 99801, 2634 | 81587, 2635 | -79793, 2636 | -18547, 2637 | -83086, 2638 | 69512, 2639 | 33127, 2640 | -92145, 2641 | -88497, 2642 | 47703, 2643 | 59527, 2644 | 1909, 2645 | 88785, 2646 | -88882, 2647 | 69188, 2648 | -46131, 2649 | -5589, 2650 | -15086, 2651 | 36255, 2652 | -53238, 2653 | -33009, 2654 | 82664, 2655 | 53901, 2656 | 35939, 2657 | -42946, 2658 | -25571, 2659 | 33298, 2660 | 69291, 2661 | 53199, 2662 | 74746, 2663 | -40127, 2664 | -39050, 2665 | 91033, 2666 | 51717, 2667 | -98048, 2668 | 87240, 2669 | 36172, 2670 | 65453, 2671 | -94425, 2672 | -63694, 2673 | -30027, 2674 | 59004, 2675 | 88660, 2676 | 3649, 2677 | -20267, 2678 | -52565, 2679 | -67321, 2680 | 34037, 2681 | 4320, 2682 | 91515, 2683 | -56753, 2684 | 60115, 2685 | 27134, 2686 | 68617, 2687 | -61395, 2688 | -26503, 2689 | -98929, 2690 | -8849, 2691 | -63318, 2692 | 10709, 2693 | -16151, 2694 | 61905, 2695 | -95785, 2696 | 5262, 2697 | 23670, 2698 | -25277, 2699 | 90206, 2700 | -19391, 2701 | 45735, 2702 | 37208, 2703 | -31992, 2704 | -92450, 2705 | 18516, 2706 | -90452, 2707 | -58870, 2708 | -58602, 2709 | 93383, 2710 | 14333, 2711 | 17994, 2712 | 82411, 2713 | -54126, 2714 | -32576, 2715 | 35440, 2716 | -60526, 2717 | -78764, 2718 | -25069, 2719 | -9022, 2720 | -394, 2721 | 92186, 2722 | -38057, 2723 | 55328, 2724 | -61569, 2725 | 67780, 2726 | 77169, 2727 | 19546, 2728 | -92664, 2729 | -94948, 2730 | 44484, 2731 | -13439, 2732 | 83529, 2733 | 27518, 2734 | -48333, 2735 | 72998, 2736 | 38342, 2737 | -90553, 2738 | -98578, 2739 | -76906, 2740 | 81515, 2741 | -16464, 2742 | 78439, 2743 | 92529, 2744 | 35225, 2745 | -39968, 2746 | -10130, 2747 | -7845, 2748 | -32245, 2749 | -74955, 2750 | -74996, 2751 | 67731, 2752 | -13897, 2753 | -82493, 2754 | 33407, 2755 | 93619, 2756 | 59560, 2757 | -24404, 2758 | -57553, 2759 | 19486, 2760 | -45341, 2761 | 34098, 2762 | -24978, 2763 | -33612, 2764 | 79058, 2765 | 71847, 2766 | 76713, 2767 | -95422, 2768 | 6421, 2769 | -96075, 2770 | -59130, 2771 | -28976, 2772 | -16922, 2773 | -62203, 2774 | 69970, 2775 | 68331, 2776 | 21874, 2777 | 40551, 2778 | 89650, 2779 | 51908, 2780 | 58181, 2781 | 66480, 2782 | -68177, 2783 | 34323, 2784 | -3046, 2785 | -49656, 2786 | -59758, 2787 | 43564, 2788 | -10960, 2789 | -30796, 2790 | 15473, 2791 | -20216, 2792 | 46085, 2793 | -85355, 2794 | 41515, 2795 | -30669, 2796 | -87498, 2797 | 57711, 2798 | 56067, 2799 | 63199, 2800 | -83805, 2801 | 62042, 2802 | 91213, 2803 | -14606, 2804 | 4394, 2805 | -562, 2806 | 74913, 2807 | 10406, 2808 | 96810, 2809 | -61595, 2810 | 32564, 2811 | 31640, 2812 | -9732, 2813 | 42058, 2814 | 98052, 2815 | -7908, 2816 | -72330, 2817 | 1558, 2818 | -80301, 2819 | 34878, 2820 | 32900, 2821 | 3939, 2822 | -8824, 2823 | 88316, 2824 | 20937, 2825 | 21566, 2826 | -3218, 2827 | -66080, 2828 | -31620, 2829 | 86859, 2830 | 54289, 2831 | 90476, 2832 | -42889, 2833 | -15016, 2834 | -18838, 2835 | 75456, 2836 | 30159, 2837 | -67101, 2838 | 42328, 2839 | -92703, 2840 | 85850, 2841 | -5475, 2842 | 23470, 2843 | -80806, 2844 | 68206, 2845 | 17764, 2846 | 88235, 2847 | 46421, 2848 | -41578, 2849 | 74005, 2850 | -81142, 2851 | 80545, 2852 | 20868, 2853 | -1560, 2854 | 64017, 2855 | 83784, 2856 | 68863, 2857 | -97516, 2858 | -13016, 2859 | -72223, 2860 | 79630, 2861 | -55692, 2862 | 82255, 2863 | 88467, 2864 | 28007, 2865 | -34686, 2866 | -69049, 2867 | -41677, 2868 | 88535, 2869 | -8217, 2870 | 68060, 2871 | -51280, 2872 | 28971, 2873 | 49088, 2874 | 49235, 2875 | 26905, 2876 | -81117, 2877 | -44888, 2878 | 40623, 2879 | 74337, 2880 | -24662, 2881 | 97476, 2882 | 79542, 2883 | -72082, 2884 | -35093, 2885 | 98175, 2886 | -61761, 2887 | -68169, 2888 | 59697, 2889 | -62542, 2890 | -72965, 2891 | 59883, 2892 | -64026, 2893 | -37656, 2894 | -92392, 2895 | -12113, 2896 | -73495, 2897 | 98258, 2898 | 68379, 2899 | -21545, 2900 | 64607, 2901 | -70957, 2902 | -92254, 2903 | -97460, 2904 | -63436, 2905 | -8853, 2906 | -19357, 2907 | -51965, 2908 | -76582, 2909 | 12687, 2910 | -49712, 2911 | 45413, 2912 | -60043, 2913 | 33496, 2914 | 31539, 2915 | -57347, 2916 | 41837, 2917 | 67280, 2918 | -68813, 2919 | 52088, 2920 | -13155, 2921 | -86430, 2922 | -15239, 2923 | -45030, 2924 | 96041, 2925 | 18749, 2926 | -23992, 2927 | 46048, 2928 | 35243, 2929 | -79450, 2930 | 85425, 2931 | -58524, 2932 | 88781, 2933 | -39454, 2934 | 53073, 2935 | -48864, 2936 | -82289, 2937 | 39086, 2938 | 82540, 2939 | -11555, 2940 | 25014, 2941 | -5431, 2942 | -39585, 2943 | -89526, 2944 | 2705, 2945 | 31953, 2946 | -81611, 2947 | 36985, 2948 | -56022, 2949 | 68684, 2950 | -27101, 2951 | 11422, 2952 | 64655, 2953 | -26965, 2954 | -63081, 2955 | -13840, 2956 | -91003, 2957 | -78147, 2958 | -8966, 2959 | 41488, 2960 | 1988, 2961 | 99021, 2962 | -61575, 2963 | -47060, 2964 | 65260, 2965 | -23844, 2966 | -21781, 2967 | -91865, 2968 | -19607, 2969 | 44808, 2970 | 2890, 2971 | 63692, 2972 | -88663, 2973 | -58272, 2974 | 15970, 2975 | -65195, 2976 | -45416, 2977 | -48444, 2978 | -78226, 2979 | -65332, 2980 | -24568, 2981 | 42833, 2982 | -1806, 2983 | -71595, 2984 | 80002, 2985 | -52250, 2986 | 30952, 2987 | 48452, 2988 | -90106, 2989 | 31015, 2990 | -22073, 2991 | 62339, 2992 | 63318, 2993 | 78391, 2994 | 28699, 2995 | 77900, 2996 | -4026, 2997 | -76870, 2998 | -45943, 2999 | 33665, 3000 | 9174, 3001 | -84360, 3002 | -22684, 3003 | -16832, 3004 | -67949, 3005 | -38077, 3006 | -38987, 3007 | -32847, 3008 | 51443, 3009 | -53580, 3010 | -13505, 3011 | 9344, 3012 | -92337, 3013 | 26585, 3014 | 70458, 3015 | -52764, 3016 | -67471, 3017 | -68411, 3018 | -1119, 3019 | -2072, 3020 | -93476, 3021 | 67981, 3022 | 40887, 3023 | -89304, 3024 | -12235, 3025 | 41488, 3026 | 1454, 3027 | 5355, 3028 | -34855, 3029 | -72080, 3030 | 24514, 3031 | -58305, 3032 | 3340, 3033 | 34331, 3034 | 8731, 3035 | 77451, 3036 | -64983, 3037 | -57876, 3038 | 82874, 3039 | 62481, 3040 | -32754, 3041 | -39902, 3042 | 22451, 3043 | -79095, 3044 | -23904, 3045 | 78409, 3046 | -7418, 3047 | 77916, 3048 | ] 3049 | import time 3050 | 3051 | start = time.time() 3052 | solution = Solution() 3053 | print(solution.threeSum(inputs)) 3054 | print(time.time() - start) 3055 | -------------------------------------------------------------------------------- /code/150. 逆波兰表达式求值.py: -------------------------------------------------------------------------------- 1 | # Author: BeiYu 2 | # Github: https://github.com/beiyuouo 3 | # Date : 2021/4/14 01:38 4 | # Description: 5 | 6 | __author__ = "BeiYu" 7 | 8 | from typing import List 9 | 10 | 11 | class Solution: 12 | def evalRPN(self, tokens: List[str]) -> int: 13 | symbols = ['+', '-', '*', '/'] 14 | 15 | class Stack(object): 16 | def __init__(self): 17 | self.stack = [] 18 | 19 | def top(self): 20 | return self.stack[-1] 21 | 22 | def pop(self): 23 | self.stack.pop(-1) 24 | 25 | def push(self, x): 26 | self.stack.append(x) 27 | 28 | stk = Stack() 29 | 30 | for token in tokens: 31 | if token in symbols: 32 | y = stk.top() 33 | stk.pop() 34 | x = stk.top() 35 | stk.pop() 36 | 37 | if token == '+': 38 | z = x + y 39 | elif token == '-': 40 | z = x - y 41 | elif token == '*': 42 | z = x * y 43 | else: 44 | z = int(x / y) 45 | stk.push(z) 46 | else: 47 | stk.push(int(token)) 48 | 49 | return stk.top() 50 | -------------------------------------------------------------------------------- /code/1512. 好数对的数目.py: -------------------------------------------------------------------------------- 1 | # Author: BeiYu 2 | # Github: https://github.com/beiyuouo 3 | # Date : 2021/3/22 13:42 4 | # Description: 5 | 6 | __author__ = "BeiYu" 7 | 8 | from typing import List 9 | 10 | 11 | class Solution: 12 | def numIdenticalPairs(self, nums: List[int]) -> int: 13 | cnt = 0 14 | for i in range(len(nums)): 15 | for j in range(i+1, len(nums)): 16 | if nums[i] == nums[j]: 17 | cnt += 1 18 | return cnt 19 | -------------------------------------------------------------------------------- /code/155. 最小栈.py: -------------------------------------------------------------------------------- 1 | # Author: BeiYu 2 | # Github: https://github.com/beiyuouo 3 | # Date : 2021/4/8 02:07 4 | # Description: 5 | 6 | __author__ = "BeiYu" 7 | 8 | 9 | class MinStack: 10 | 11 | def __init__(self): 12 | """ 13 | initialize your data structure here. 14 | """ 15 | self.stk = [] 16 | self.min_stk = [] 17 | 18 | def push(self, val: int) -> None: 19 | self.stk.append(val) 20 | if len(self.min_stk): self.min_stk.append(min(self.min_stk[-1], val)) 21 | else: self.min_stk.append(val) 22 | 23 | def pop(self) -> None: 24 | self.stk.pop(-1) 25 | self.min_stk.pop(-1) 26 | 27 | def top(self) -> int: 28 | return self.stk[-1] 29 | 30 | def getMin(self) -> int: 31 | return self.min_stk[-1] 32 | 33 | # Your MinStack object will be instantiated and called as such: 34 | # obj = MinStack() 35 | # obj.push(val) 36 | # obj.pop() 37 | # param_3 = obj.top() 38 | # param_4 = obj.getMin() 39 | -------------------------------------------------------------------------------- /code/1572. 矩阵对角线元素的和.py: -------------------------------------------------------------------------------- 1 | # Author: BeiYu 2 | # Github: https://github.com/beiyuouo 3 | # Date : 2021/3/19 16:56 4 | # Description: 5 | 6 | __author__ = "BeiYu" 7 | 8 | from typing import List 9 | 10 | 11 | class Solution: 12 | def diagonalSum(self, mat: List[List[int]]) -> int: 13 | return sum([mat[x][x] for x in range(len(mat))]) + sum([mat[x][len(mat) - 1 - x] for x in range(len(mat))]) \ 14 | - (0 if len(mat) % 2 == 0 else mat[len(mat) // 2][len(mat) // 2]) 15 | -------------------------------------------------------------------------------- /code/1588. 所有奇数长度子数组的和.py: -------------------------------------------------------------------------------- 1 | # Author: BeiYu 2 | # Github: https://github.com/beiyuouo 3 | # Date : 2021/3/21 17:07 4 | # Description: 5 | 6 | __author__ = "BeiYu" 7 | 8 | from typing import List 9 | import math 10 | 11 | 12 | class Solution: 13 | def sumOddLengthSubarrays(self, arr: List[int]) -> int: 14 | res = 0 15 | for i in range(len(arr)): 16 | res += arr[i] * ((i//2 + 1) * ((len(arr) - i - 1) // 2 + 1) 17 | + math.ceil(i / 2) * math.ceil((len(arr) - i - 1) / 2)) 18 | # print(i, (i//2 + 1) * ((len(arr) - i - 1) // 2 + 1), 19 | # math.ceil(i / 2) * math.ceil((len(arr) - i - 1) / 2)) 20 | return res 21 | 22 | 23 | if __name__ == '__main__': 24 | print(Solution().sumOddLengthSubarrays([1, 4, 2, 5, 3])) 25 | -------------------------------------------------------------------------------- /code/160. 相交链表.py: -------------------------------------------------------------------------------- 1 | # Author: BeiYu 2 | # Github: https://github.com/beiyuouo 3 | # Date : 2021/4/8 02:10 4 | # Description: 5 | 6 | __author__ = "BeiYu" 7 | 8 | 9 | # Definition for singly-linked list. 10 | class ListNode: 11 | def __init__(self, x): 12 | self.val = x 13 | self.next = None 14 | 15 | 16 | class Solution: 17 | def getIntersectionNode(self, headA: ListNode, headB: ListNode) -> ListNode: 18 | q = headA 19 | map = {} 20 | while q: 21 | map[q] = 1 22 | q = q.next 23 | 24 | q = headB 25 | while q: 26 | if q in map.keys(): 27 | return q 28 | q = q.next 29 | 30 | return None 31 | -------------------------------------------------------------------------------- /code/1603. 设计停车系统.py: -------------------------------------------------------------------------------- 1 | # Author: BeiYu 2 | # Github: https://github.com/beiyuouo 3 | # Date : 2021/3/22 13:26 4 | # Description: 5 | 6 | __author__ = "BeiYu" 7 | 8 | 9 | class ParkingSystem: 10 | 11 | def __init__(self, big: int, medium: int, small: int): 12 | self.remaining = [0, big, medium, small] 13 | 14 | def addCar(self, carType: int) -> bool: 15 | if self.remaining[carType] > 0: 16 | self.remaining[carType] -= 1 17 | return True 18 | return False 19 | 20 | 21 | # Your ParkingSystem object will be instantiated and called as such: 22 | # obj = ParkingSystem(big, medium, small) 23 | # param_1 = obj.addCar(carType) 24 | 25 | if __name__ == '__main__': 26 | obj = ParkingSystem(1, 1, 0) 27 | print(obj.addCar(1)) 28 | print(obj.addCar(2)) 29 | print(obj.addCar(3)) 30 | print(obj.addCar(1)) 31 | -------------------------------------------------------------------------------- /code/1614. 括号的最大嵌套深度.py: -------------------------------------------------------------------------------- 1 | # Author: BeiYu 2 | # Github: https://github.com/beiyuouo 3 | # Date : 2021/3/17 14:33 4 | # Description: 5 | 6 | __author__ = "BeiYu" 7 | 8 | 9 | class Solution: 10 | def maxDepth(self, s: str) -> int: 11 | res = 0 12 | cur = 0 13 | for _s in s: 14 | if _s == '(': 15 | cur += 1 16 | elif _s == ')': 17 | cur -= 1 18 | res = max(res, cur) 19 | return res 20 | 21 | 22 | if __name__ == '__main__': 23 | solution = Solution() 24 | print(solution.maxDepth("(1+(2*3)+((8)/4))+1")) 25 | -------------------------------------------------------------------------------- /code/1630. 等差子数组.py: -------------------------------------------------------------------------------- 1 | # Author: BeiYu 2 | # Github: https://github.com/beiyuouo 3 | # Date : 2021/3/25 11:56 4 | # Description: 5 | 6 | __author__ = "BeiYu" 7 | 8 | from typing import List 9 | 10 | 11 | class Solution: 12 | def checkArithmeticSubarrays(self, nums: List[int], l: List[int], r: List[int]) -> List[bool]: 13 | def _check(arr: List[int]) -> bool: 14 | arr.sort() 15 | _arithmet = arr[1] - arr[0] 16 | for i in range(2, len(arr)): 17 | if arr[i] - arr[i - 1] != _arithmet: 18 | return False 19 | return True 20 | 21 | res = [] 22 | for i in range(len(l)): 23 | if _check(nums[l[i]: r[i] + 1]): 24 | res.append(True) 25 | else: 26 | res.append(False) 27 | 28 | return res 29 | -------------------------------------------------------------------------------- /code/1641. 统计字典序元音字符串的数目.py: -------------------------------------------------------------------------------- 1 | # Author: BeiYu 2 | # Github: https://github.com/beiyuouo 3 | # Date : 2021/3/24 00:39 4 | # Description: 5 | 6 | __author__ = "BeiYu" 7 | 8 | 9 | class Solution: 10 | def countVowelStrings(self, n: int) -> int: 11 | # f[i][j]表示前i位最后j结尾的方案数 12 | import numpy as np 13 | f = np.zeros((n, 5)) 14 | f[0] = np.array([1, 1, 1, 1, 1]) 15 | for i in np.arange(1, n): 16 | for j in np.arange(5): 17 | f[i][j] = f[i - 1][j] 18 | for k in np.arange(j): 19 | f[i][j] += f[i - 1][k] 20 | 21 | return int(sum(f[n - 1])) 22 | -------------------------------------------------------------------------------- /code/165. 比较版本号.py: -------------------------------------------------------------------------------- 1 | # Author: BeiYu 2 | # Github: https://github.com/beiyuouo 3 | # Date : 2021/4/12 01:10 4 | # Description: 5 | 6 | __author__ = "BeiYu" 7 | 8 | 9 | class Solution: 10 | def compareVersion(self, version1: str, version2: str) -> int: 11 | vec1 = version1.split('.') 12 | vec2 = version2.split('.') 13 | 14 | i1, i2 = 0, 0 15 | while i1 < len(vec1) or i2 < len(vec2): 16 | if i1 >= len(vec1): 17 | vec1.append('0') 18 | if i2 >= len(vec2): 19 | vec2.append('0') 20 | if int(vec1[i1]) > int(vec2[i2]): 21 | return 1 22 | elif int(vec1[i1]) < int(vec2[i2]): 23 | return -1 24 | i1 += 1 25 | i2 += 1 26 | 27 | return 0 28 | -------------------------------------------------------------------------------- /code/1662. 检查两个字符串数组是否相等.py: -------------------------------------------------------------------------------- 1 | # Author: BeiYu 2 | # Github: https://github.com/beiyuouo 3 | # Date : 2021/3/17 14:33 4 | # Description: 5 | 6 | __author__ = "BeiYu" 7 | 8 | from typing import List 9 | 10 | 11 | class Solution: 12 | def arrayStringsAreEqual(self, word1: List[str], word2: List[str]) -> bool: 13 | return ''.join(word1) == ''.join(word2) 14 | -------------------------------------------------------------------------------- /code/167. 两数之和 II - 输入有序数组.py: -------------------------------------------------------------------------------- 1 | # Author: BeiYu 2 | # Github: https://github.com/beiyuouo 3 | # Date : 2021/4/8 02:12 4 | # Description: 5 | 6 | __author__ = "BeiYu" 7 | 8 | from typing import List 9 | 10 | 11 | class Solution: 12 | def twoSum(self, numbers: List[int], target: int) -> List[int]: 13 | map = {} 14 | for i in range(len(numbers)): 15 | if numbers[i] in map.keys(): 16 | return [map[numbers[i]] + 1, i + 1] 17 | map[target - numbers[i]] = i 18 | 19 | return None 20 | -------------------------------------------------------------------------------- /code/1672. 最富有客户的资产总量.py: -------------------------------------------------------------------------------- 1 | # Author: BeiYu 2 | # Github: https://github.com/beiyuouo 3 | # Date : 2021/3/22 12:25 4 | # Description: 5 | 6 | __author__ = "BeiYu" 7 | 8 | from typing import List 9 | 10 | 11 | class Solution: 12 | def maximumWealth(self, accounts: List[List[int]]) -> int: 13 | maxx = 0 14 | for l in accounts: 15 | if sum(l) > maxx: 16 | maxx = sum(l) 17 | return maxx 18 | -------------------------------------------------------------------------------- /code/1678. 设计 Goal 解析器.py: -------------------------------------------------------------------------------- 1 | # Author: BeiYu 2 | # Github: https://github.com/beiyuouo 3 | # Date : 2021/3/16 14:13 4 | # Description: 5 | 6 | __author__ = "BeiYu" 7 | 8 | 9 | class Solution: 10 | def interpret(self, command: str) -> str: 11 | return command.replace("()", "o").replace("(al)", "al") 12 | -------------------------------------------------------------------------------- /code/168. Excel表列名称.py: -------------------------------------------------------------------------------- 1 | # Author: BeiYu 2 | # Github: https://github.com/beiyuouo 3 | # Date : 2021/4/9 11:30 4 | # Description: 5 | 6 | __author__ = "BeiYu" 7 | 8 | 9 | class Solution: 10 | def convertToTitle(self, columnNumber: int) -> str: 11 | dic = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" 12 | 13 | res = "" 14 | while columnNumber > 0: 15 | columnNumber -= 1 16 | res += dic[columnNumber % 26] 17 | columnNumber //= 26 18 | 19 | return res[::-1] 20 | -------------------------------------------------------------------------------- /code/1684. 统计一致字符串的数目.py: -------------------------------------------------------------------------------- 1 | # Author: BeiYu 2 | # Github: https://github.com/beiyuouo 3 | # Date : 2021/3/16 14:13 4 | # Description: 5 | 6 | __author__ = "BeiYu" 7 | 8 | from typing import List 9 | 10 | 11 | class Solution: 12 | def countConsistentStrings(self, allowed: str, words: List[str]) -> int: 13 | def _check(_str: str): 14 | for char in _str: 15 | if char not in allowed: 16 | return False 17 | return True 18 | 19 | cnt = 0 20 | for word in words: 21 | if _check(word): 22 | cnt += 1 23 | 24 | return cnt 25 | -------------------------------------------------------------------------------- /code/1688. 比赛中的配对次数.py: -------------------------------------------------------------------------------- 1 | # Author: BeiYu 2 | # Github: https://github.com/beiyuouo 3 | # Date : 2021/3/21 17:06 4 | # Description: 5 | 6 | __author__ = "BeiYu" 7 | 8 | 9 | class Solution: 10 | def numberOfMatches(self, n: int) -> int: 11 | res = 0 12 | while n > 1: 13 | res += n // 2 14 | n = n // 2 if n % 2 == 0 else n // 2 + 1 15 | return res 16 | -------------------------------------------------------------------------------- /code/169. 多数元素.py: -------------------------------------------------------------------------------- 1 | # Author: BeiYu 2 | # Github: https://github.com/beiyuouo 3 | # Date : 2021/4/9 11:31 4 | # Description: 5 | 6 | __author__ = "BeiYu" 7 | 8 | from typing import List 9 | 10 | 11 | class Solution: 12 | def majorityElement(self, nums: List[int]) -> int: 13 | num = nums[0] 14 | count = 1 15 | for i in range(1, len(nums)): 16 | if nums[i] == num: 17 | count += 1 18 | else: 19 | count -= 1 20 | if count == 0: 21 | num = nums[0] 22 | count = 1 23 | return num 24 | -------------------------------------------------------------------------------- /code/1704. 判断字符串的两半是否相似.py: -------------------------------------------------------------------------------- 1 | # Author: BeiYu 2 | # Github: https://github.com/beiyuouo 3 | # Date : 2021/3/24 00:47 4 | # Description: 5 | 6 | __author__ = "BeiYu" 7 | 8 | 9 | class Solution: 10 | def halvesAreAlike(self, s: str) -> bool: 11 | n = len(s) // 2 12 | s1, s2 = s[:n], s[n:] 13 | cnt = 0 14 | 15 | def _is_vowel(ch: str): 16 | return ch in ['a', 'e', 'i', 'o', 'u', 'A', 'E', 'I', 'O', 'U'] 17 | 18 | for i in range(n): 19 | if _is_vowel(s1[i]): 20 | cnt += 1 21 | if _is_vowel(s2[i]): 22 | cnt -= 1 23 | return cnt == 0 24 | -------------------------------------------------------------------------------- /code/171. Excel表列序号.py: -------------------------------------------------------------------------------- 1 | # Author: BeiYu 2 | # Github: https://github.com/beiyuouo 3 | # Date : 2021/4/9 11:31 4 | # Description: 5 | 6 | __author__ = "BeiYu" 7 | 8 | 9 | class Solution: 10 | def titleToNumber(self, columnTitle: str) -> int: 11 | dic = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" 12 | map = {} 13 | for i in range(len(dic)): 14 | map[dic[i]] = i + 1 15 | 16 | res = 0 17 | columnTitle = columnTitle[::-1] 18 | while len(columnTitle) > 0: 19 | res += map[columnTitle[-1]] 20 | res *= 26 21 | columnTitle = columnTitle[:-1] 22 | 23 | return res 24 | -------------------------------------------------------------------------------- /code/172. 阶乘后的零.py: -------------------------------------------------------------------------------- 1 | # Author: BeiYu 2 | # Github: https://github.com/beiyuouo 3 | # Date : 2021/4/10 14:11 4 | # Description: 5 | 6 | __author__ = "BeiYu" 7 | 8 | 9 | class Solution: 10 | def trailingZeroes(self, n: int) -> int: 11 | count = 0 12 | pwer = 5 13 | while n >= pwer: 14 | count += n // pwer 15 | pwer *= 5 16 | return count 17 | -------------------------------------------------------------------------------- /code/1720. 解码异或后的数组.py: -------------------------------------------------------------------------------- 1 | # Author: BeiYu 2 | # Github: https://github.com/beiyuouo 3 | # Date : 2021/3/14 13:59 4 | # Description: 5 | 6 | __author__ = "BeiYu" 7 | 8 | from typing import List 9 | 10 | 11 | class Solution: 12 | def decode(self, encoded: List[int], first: int) -> List[int]: 13 | curr = first 14 | res = [curr] 15 | for i in encoded: 16 | curr = curr ^ i 17 | res.append(curr) 18 | return res 19 | -------------------------------------------------------------------------------- /code/1732. 找到最高海拔.py: -------------------------------------------------------------------------------- 1 | # Author: BeiYu 2 | # Github: https://github.com/beiyuouo 3 | # Date : 2021/3/19 16:55 4 | # Description: 5 | 6 | __author__ = "BeiYu" 7 | 8 | from typing import List 9 | 10 | 11 | class Solution: 12 | def largestAltitude(self, gain: List[int]) -> int: 13 | res = 0 14 | cur = 0 15 | for x in gain: 16 | cur += x 17 | res = max(res, cur) 18 | return res 19 | -------------------------------------------------------------------------------- /code/1768. 交替合并字符串.py: -------------------------------------------------------------------------------- 1 | # Author: BeiYu 2 | # Github: https://github.com/beiyuouo 3 | # Date : 2021/3/24 00:47 4 | # Description: 5 | 6 | __author__ = "BeiYu" 7 | 8 | 9 | class Solution: 10 | def mergeAlternately(self, word1: str, word2: str) -> str: 11 | h1, h2 = 0, 0 12 | new_str: str = "" 13 | while h1 < len(word1) or h2 < len(word2): 14 | if h1 < len(word1): 15 | new_str += word1[h1] 16 | if h2 < len(word2): 17 | new_str += word2[h2] 18 | 19 | h1 += 1 20 | h2 += 1 21 | return new_str 22 | -------------------------------------------------------------------------------- /code/1773. 统计匹配检索规则的物品数量.py: -------------------------------------------------------------------------------- 1 | # Author: BeiYu 2 | # Github: https://github.com/beiyuouo 3 | # Date : 2021/3/22 13:48 4 | # Description: 5 | 6 | __author__ = "BeiYu" 7 | 8 | from typing import List 9 | 10 | 11 | class Solution: 12 | def countMatches(self, items: List[List[str]], ruleKey: str, ruleValue: str) -> int: 13 | str2idx = {"type": 0, "color": 1, "name": 2} 14 | ruleKey = str2idx[ruleKey] 15 | cnt = 0 16 | for item in items: 17 | if item[ruleKey] == ruleValue: 18 | cnt += 1 19 | return cnt 20 | -------------------------------------------------------------------------------- /code/190. 颠倒二进制位.py: -------------------------------------------------------------------------------- 1 | # Author: BeiYu 2 | # Github: https://github.com/beiyuouo 3 | # Date : 2021/4/10 15:38 4 | # Description: 5 | 6 | __author__ = "BeiYu" 7 | 8 | 9 | class Solution: 10 | def reverseBits(self, n: int) -> int: 11 | _32bit = ['0' for i in range(32)] 12 | _32bit[-len(bin(n)[2:])] = bin(n)[2:] 13 | return int(''.join(_32bit[::-1]), 2) 14 | -------------------------------------------------------------------------------- /code/191. 位1的个数.py: -------------------------------------------------------------------------------- 1 | # Author: BeiYu 2 | # Github: https://github.com/beiyuouo 3 | # Date : 2021/3/22 13:31 4 | # Description: 5 | 6 | __author__ = "BeiYu" 7 | 8 | 9 | class Solution: 10 | def hammingWeight(self, n: int) -> int: 11 | n = bin(n) 12 | s = str(n) 13 | cnt = 0 14 | for i in range(len(s)): 15 | if s[i] == '1': 16 | cnt += 1 17 | # print(i) 18 | 19 | return cnt 20 | -------------------------------------------------------------------------------- /code/2. 两数相加.py: -------------------------------------------------------------------------------- 1 | # Author: BeiYu 2 | # Github: https://github.com/beiyuouo 3 | # Date : 2021/3/28 00:26 4 | # Description: 5 | 6 | __author__ = "BeiYu" 7 | 8 | 9 | # Definition for singly-linked list. 10 | class ListNode: 11 | def __init__(self, val=0, next=None): 12 | self.val = val 13 | self.next = next 14 | 15 | 16 | class Solution: 17 | def addTwoNumbers(self, l1: ListNode, l2: ListNode) -> ListNode: 18 | res = None 19 | rt = None 20 | cur = 0 21 | flag = False 22 | 23 | def _addnode(_res, x: int): 24 | new_node = ListNode(val=x) 25 | print(x) 26 | if _res: 27 | _res.next = new_node 28 | _res = new_node 29 | return _res 30 | 31 | while l1 or l2: 32 | if l1: 33 | cur += l1.val 34 | if l2: 35 | cur += l2.val 36 | 37 | if not res: 38 | flag = True 39 | res = _addnode(res, cur % 10) 40 | 41 | if flag: 42 | flag = False 43 | rt = res 44 | 45 | cur //= 10 46 | if l1: 47 | l1 = l1.next 48 | if l2: 49 | l2 = l2.next 50 | 51 | while cur > 0: 52 | res = _addnode(res, cur % 10) 53 | cur //= 10 54 | 55 | print(rt.val) 56 | return rt 57 | -------------------------------------------------------------------------------- /code/20. 有效的括号.py: -------------------------------------------------------------------------------- 1 | # Author: BeiYu 2 | # Github: https://github.com/beiyuouo 3 | # Date : 2021/3/29 01:09 4 | # Description: 5 | 6 | __author__ = "BeiYu" 7 | 8 | 9 | class Solution: 10 | def isValid(self, s: str) -> bool: 11 | pair_dict = {')': '(', ']': '[', '}': '{'} 12 | 13 | class Stack: 14 | def __init__(self): 15 | self.stk = [] 16 | 17 | def get_top(self): 18 | return None if len(self.stk) == 0 else self.stk[-1] 19 | 20 | def pop(self): 21 | self.stk.pop(-1) 22 | 23 | def push(self, _ch: str): 24 | self.stk.append(_ch) 25 | 26 | def __len__(self): 27 | return len(self.stk) 28 | 29 | stack = Stack() 30 | 31 | for ch in s: 32 | if ch not in pair_dict.keys(): 33 | stack.push(ch) 34 | else: 35 | if stack.get_top() != pair_dict[ch]: 36 | return False 37 | else: 38 | stack.pop() 39 | if len(stack) > 0: 40 | return False 41 | return True -------------------------------------------------------------------------------- /code/202. 快乐数.py: -------------------------------------------------------------------------------- 1 | # Author: BeiYu 2 | # Github: https://github.com/beiyuouo 3 | # Date : 2021/4/25 10:04 4 | # Description: 5 | 6 | __author__ = "BeiYu" 7 | 8 | 9 | class Solution: 10 | def isHappy(self, n: int) -> bool: 11 | def getsqsum(x: int) -> int: 12 | res = 0 13 | for ch in str(x): 14 | res += int(ch) ** 2 15 | return res 16 | 17 | dic = {} 18 | dic[n] = 1 19 | while True: 20 | n = getsqsum(n) 21 | if n == 1: 22 | return True 23 | if n in dic.keys(): 24 | break 25 | dic[n] = 1 26 | return False 27 | -------------------------------------------------------------------------------- /code/204. 计数质数.py: -------------------------------------------------------------------------------- 1 | # Author: BeiYu 2 | # Github: https://github.com/beiyuouo 3 | # Date : 2021/4/10 15:43 4 | # Description: 5 | 6 | __author__ = "BeiYu" 7 | 8 | 9 | class Solution: 10 | def countPrimes(self, n: int) -> int: 11 | is_prime = [1 for i in range(min(5, n))] 12 | is_prime[0] = is_prime[1] = 0 13 | prime = [] 14 | for i in range(2, n): 15 | if is_prime[i]: 16 | prime.append(i) 17 | j = i * i 18 | while j < n: 19 | is_prime[j] = 0 20 | j += i 21 | return len(prime) 22 | -------------------------------------------------------------------------------- /code/205. 同构字符串.py: -------------------------------------------------------------------------------- 1 | # Author: BeiYu 2 | # Github: https://github.com/beiyuouo 3 | # Date : 2021/4/17 01:43 4 | # Description: 5 | 6 | __author__ = "BeiYu" 7 | 8 | 9 | class Solution: 10 | def isIsomorphic(self, s: str, t: str) -> bool: 11 | 12 | def reformat(_s: str) -> str: 13 | itr = 0 14 | dic = {} 15 | _ss = "" 16 | for _ch in _s: 17 | if _ch not in dic.keys(): 18 | dic[_ch] = itr 19 | itr += 1 20 | _ss += chr(ord("a")+dic[_ch]) 21 | return _ss 22 | 23 | return reformat(s) == reformat(t) 24 | -------------------------------------------------------------------------------- /code/21. 合并两个有序链表.py: -------------------------------------------------------------------------------- 1 | # Author: BeiYu 2 | # Github: https://github.com/beiyuouo 3 | # Date : 2021/3/29 01:09 4 | # Description: 5 | 6 | __author__ = "BeiYu" 7 | 8 | import math 9 | 10 | 11 | # Definition for singly-linked list. 12 | class ListNode: 13 | def __init__(self, val=0, next=None): 14 | self.val = val 15 | self.next = next 16 | 17 | 18 | class Solution: 19 | def mergeTwoLists(self, l1: ListNode, l2: ListNode) -> ListNode: 20 | rt = p = ListNode() 21 | 22 | def _add(x: int, _p: ListNode) -> ListNode: 23 | _p.next = ListNode(x) 24 | _p = _p.next 25 | return _p 26 | 27 | def _get_next(_l: ListNode): 28 | if _l: 29 | return _l.val 30 | return math.inf 31 | 32 | while l1 or l2: 33 | if _get_next(l1) < _get_next(l2): 34 | p = _add(_get_next(l1), p) 35 | l1 = l1.next 36 | else: 37 | p = _add(_get_next(l2), p) 38 | l2 = l2.next 39 | 40 | return rt.next 41 | -------------------------------------------------------------------------------- /code/217. 存在重复元素.py: -------------------------------------------------------------------------------- 1 | # Author: BeiYu 2 | # Github: https://github.com/beiyuouo 3 | # Date : 2021/4/25 09:48 4 | # Description: 5 | 6 | __author__ = "BeiYu" 7 | 8 | from typing import List 9 | 10 | 11 | class Solution: 12 | def containsDuplicate(self, nums: List[int]) -> bool: 13 | import numpy as np 14 | return np.unique(nums).shape[0] != len(nums) 15 | -------------------------------------------------------------------------------- /code/225. 用队列实现栈.py: -------------------------------------------------------------------------------- 1 | # Author: BeiYu 2 | # Github: https://github.com/beiyuouo 3 | # Date : 2021/4/27 00:59 4 | # Description: 5 | 6 | __author__ = "BeiYu" 7 | 8 | from queue import LifoQueue 9 | 10 | 11 | class MyStack: 12 | 13 | def __init__(self): 14 | """ 15 | Initialize your data structure here. 16 | """ 17 | self.q = LifoQueue() 18 | 19 | def push(self, x: int) -> None: 20 | """ 21 | Push element x onto stack. 22 | """ 23 | n = self.q.qsize() 24 | self.q.put(x) 25 | 26 | def pop(self) -> int: 27 | """ 28 | Removes the element on top of the stack and returns that element. 29 | """ 30 | return self.q.get() 31 | 32 | def top(self) -> int: 33 | """ 34 | Get the top element. 35 | """ 36 | return self.q.queue[-1] 37 | 38 | def empty(self) -> bool: 39 | """ 40 | Returns whether the stack is empty. 41 | """ 42 | return self.q.empty() 43 | -------------------------------------------------------------------------------- /code/234. 回文链表.py: -------------------------------------------------------------------------------- 1 | # Author: BeiYu 2 | # Github: https://github.com/beiyuouo 3 | # Date : 2021/4/27 01:39 4 | # Description: 5 | 6 | __author__ = "BeiYu" 7 | 8 | 9 | # Definition for singly-linked list. 10 | class ListNode: 11 | def __init__(self, val=0, next=None): 12 | self.val = val 13 | self.next = next 14 | 15 | 16 | class Solution: 17 | def isPalindrome(self, head: ListNode) -> bool: 18 | vals = [] 19 | q = head 20 | while q is not None: 21 | vals.append(q.val) 22 | q = q.next 23 | return vals == vals[::-1] 24 | 25 | -------------------------------------------------------------------------------- /code/237. 删除链表中的节点.py: -------------------------------------------------------------------------------- 1 | # Author: BeiYu 2 | # Github: https://github.com/beiyuouo 3 | # Date : 2021/3/15 14:06 4 | # Description: 5 | 6 | __author__ = "BeiYu" 7 | 8 | 9 | # Definition for singly-linked list. 10 | # class ListNode: 11 | # def __init__(self, x): 12 | # self.val = x 13 | # self.next = None 14 | 15 | class Solution: 16 | def deleteNode(self, node): 17 | """ 18 | :type node: ListNode 19 | :rtype: void Do not return anything, modify node in-place instead. 20 | """ 21 | node.val = node.next.val 22 | node.next = node.next.next 23 | 24 | -------------------------------------------------------------------------------- /code/26. 删除有序数组中的重复项.py: -------------------------------------------------------------------------------- 1 | # Author: BeiYu 2 | # Github: https://github.com/beiyuouo 3 | # Date : 2021/4/1 01:32 4 | # Description: 5 | 6 | __author__ = "BeiYu" 7 | 8 | from typing import List 9 | 10 | 11 | class Solution: 12 | def removeDuplicates(self, nums: List[int]) -> int: 13 | if len(nums) == 0: 14 | return 0 15 | h = 0 16 | for i in range(1, len(nums)): 17 | if nums[i] == nums[i - 1]: 18 | continue 19 | h += 1 20 | nums[h] = nums[i] 21 | return h + 1 22 | -------------------------------------------------------------------------------- /code/263. 丑数.py: -------------------------------------------------------------------------------- 1 | # Author: BeiYu 2 | # Github: https://github.com/beiyuouo 3 | # Date : 2021/4/16 13:47 4 | # Description: 5 | 6 | __author__ = "BeiYu" 7 | 8 | import math 9 | 10 | 11 | class Solution: 12 | def isUgly(self, n: int) -> bool: 13 | if n == 0 or n == 1 or n == -1: 14 | return False 15 | 16 | while n % 2 == 0: 17 | n //= 2 18 | 19 | while n % 3 == 0: 20 | n //= 3 21 | 22 | while n % 5 == 0: 23 | n //= 5 24 | 25 | if n == 1: 26 | return True 27 | else: 28 | return False 29 | -------------------------------------------------------------------------------- /code/27. 移除元素.py: -------------------------------------------------------------------------------- 1 | # Author: BeiYu 2 | # Github: https://github.com/beiyuouo 3 | # Date : 2021/4/1 01:37 4 | # Description: 5 | 6 | __author__ = "BeiYu" 7 | 8 | from typing import List 9 | 10 | 11 | class Solution: 12 | def removeElement(self, nums: List[int], val: int) -> int: 13 | h = 0 14 | for i in range(len(nums)): 15 | if nums[i] == val: 16 | continue 17 | nums[h] = nums[i] 18 | h += 1 19 | return h 20 | -------------------------------------------------------------------------------- /code/28. 实现 strStr().py: -------------------------------------------------------------------------------- 1 | # Author: BeiYu 2 | # Github: https://github.com/beiyuouo 3 | # Date : 2021/4/1 01:39 4 | # Description: 5 | 6 | __author__ = "BeiYu" 7 | 8 | 9 | class Solution: 10 | def strStr(self, haystack: str, needle: str) -> int: 11 | return haystack.find(needle) 12 | -------------------------------------------------------------------------------- /code/283. 移动零.py: -------------------------------------------------------------------------------- 1 | # Author: BeiYu 2 | # Github: https://github.com/beiyuouo 3 | # Date : 2021/4/24 00:31 4 | # Description: 5 | 6 | __author__ = "BeiYu" 7 | 8 | from typing import List 9 | 10 | 11 | class Solution: 12 | def moveZeroes(self, nums: List[int]) -> None: 13 | """ 14 | Do not return anything, modify nums in-place instead. 15 | """ 16 | i, cnt = 0, 0 17 | while i < len(nums): 18 | if nums[i] == 0 and len(nums) - i - 1 >= cnt: 19 | for j in range(i, len(nums) - 1): 20 | nums[j] = nums[j + 1] 21 | nums[-1] = 0 22 | cnt += 1 23 | else: 24 | i += 1 25 | -------------------------------------------------------------------------------- /code/3. 无重复字符的最长子串.py: -------------------------------------------------------------------------------- 1 | # Author: BeiYu 2 | # Github: https://github.com/beiyuouo 3 | # Date : 2021/3/29 01:00 4 | # Description: 5 | 6 | __author__ = "BeiYu" 7 | 8 | 9 | class Solution: 10 | def lengthOfLongestSubstring(self, s: str) -> int: 11 | head = 0 12 | res = 0 13 | last_letter = {} 14 | 15 | def _last(_ch: str) -> int: 16 | if _ch not in last_letter.keys(): 17 | return -1 18 | return last_letter[_ch] 19 | 20 | def _update(_ch: str, _idx: int) -> None: 21 | last_letter[_ch] = _idx 22 | 23 | for i in range(len(s)): 24 | if _last(s[i]) != -1: 25 | head = max(head, _last(s[i])+1) 26 | res = max(res, i - head + 1) 27 | _update(s[i], i) 28 | 29 | return res 30 | -------------------------------------------------------------------------------- /code/300. 最长递增子序列.py: -------------------------------------------------------------------------------- 1 | # Author: BeiYu 2 | # Github: https://github.com/beiyuouo 3 | # Date : 2021/4/25 10:16 4 | # Description: 5 | 6 | __author__ = "BeiYu" 7 | 8 | from typing import List 9 | 10 | 11 | class Solution: 12 | def lengthOfLIS(self, nums: List[int]) -> int: 13 | f = [0 for i in range(len(nums))] 14 | f[0] = 1 15 | for i in range(1, len(nums)): 16 | f[i] = 1 17 | for j in range(i): 18 | if nums[j] < nums[i]: 19 | f[i] = max(f[i], f[j] + 1) 20 | 21 | return max(f) 22 | -------------------------------------------------------------------------------- /code/303. 区域和检索 - 数组不可变.py: -------------------------------------------------------------------------------- 1 | # Author: BeiYu 2 | # Github: https://github.com/beiyuouo 3 | # Date : 2021/3/27 00:05 4 | # Description: 5 | 6 | __author__ = "BeiYu" 7 | 8 | from typing import List 9 | 10 | 11 | class NumArray: 12 | 13 | def __init__(self, nums: List[int]): 14 | self.arrSum = [] 15 | cur = 0 16 | for i in range(len(nums)): 17 | cur += nums[i] 18 | self.arrSum.append(cur) 19 | 20 | def sumRange(self, left: int, right: int) -> int: 21 | def _getsum(x: int) -> int: 22 | return self.arrSum[x] if x >= 0 else 0 23 | 24 | return _getsum(right) - _getsum(left - 1) 25 | 26 | # Your NumArray object will be instantiated and called as such: 27 | # obj = NumArray(nums) 28 | # param_1 = obj.sumRange(left,right) 29 | -------------------------------------------------------------------------------- /code/304. 二维区域和检索 - 矩阵不可变.py: -------------------------------------------------------------------------------- 1 | # Author: BeiYu 2 | # Github: https://github.com/beiyuouo 3 | # Date : 2021/3/26 01:36 4 | # Description: 5 | 6 | __author__ = "BeiYu" 7 | 8 | from typing import List 9 | 10 | 11 | class NumMatrix: 12 | 13 | def __init__(self, matrix: List[List[int]]): 14 | self.sumMat = [] 15 | self.rowMax = len(matrix) 16 | self.colMax = len(matrix[0]) 17 | 18 | for i in range(self.rowMax): 19 | sumRow = [matrix[i][0]] 20 | for j in range(1, self.colMax): 21 | sumRow.append(sumRow[-1] + matrix[i][j]) 22 | if i > 0: 23 | for j in range(self.colMax): 24 | sumRow[j] += self.sumMat[-1][j] 25 | self.sumMat.append(sumRow) 26 | 27 | def _sumSubMat(self, row: int, col: int) -> int: 28 | if row < 0 or row > self.rowMax or col < 0 or col > self.colMax: 29 | return 0 30 | return self.sumMat[row][col] 31 | 32 | def sumRegion(self, row1: int, col1: int, row2: int, col2: int) -> int: 33 | return self._sumSubMat(row2, col2) - self._sumSubMat(row1 - 1, col2) \ 34 | - self._sumSubMat(row2, col1 - 1) + self._sumSubMat(row1 - 1, col1 - 1) 35 | 36 | 37 | # Your NumMatrix object will be instantiated and called as such: 38 | if __name__ == '__main__': 39 | obj = NumMatrix([[3, 0, 1, 4, 2], [5, 6, 3, 2, 1], [1, 2, 0, 1, 5], [4, 1, 0, 1, 7], [1, 0, 3, 0, 5]]) 40 | # [2, 1, 4, 3], [1, 1, 2, 2], [1, 2, 2, 4] 41 | print(obj.sumRegion(2, 1, 4, 3)) 42 | print(obj.sumRegion(1, 1, 2, 2)) 43 | print(obj.sumRegion(1, 2, 2, 4)) 44 | -------------------------------------------------------------------------------- /code/326. 3的幂.py: -------------------------------------------------------------------------------- 1 | # Author: BeiYu 2 | # Github: https://github.com/beiyuouo 3 | # Date : 2021/3/25 11:51 4 | # Description: 5 | 6 | __author__ = "BeiYu" 7 | 8 | import math 9 | 10 | 11 | class Solution: 12 | eps = 1e-6 13 | 14 | def isPowerOfThree(self, n: int) -> bool: 15 | if n <= 0: 16 | return False 17 | # print(math.log(n, 3)) 18 | _log = int(math.log(n, 3) + self.eps) 19 | return n == 3 ** _log 20 | 21 | 22 | if __name__ == '__main__': 23 | print(Solution().isPowerOfThree(243)) 24 | -------------------------------------------------------------------------------- /code/328. 奇偶链表.py: -------------------------------------------------------------------------------- 1 | # Author: BeiYu 2 | # Github: https://github.com/beiyuouo 3 | # Date : 2021/4/14 01:17 4 | # Description: 5 | 6 | __author__ = "BeiYu" 7 | 8 | 9 | # Definition for singly-linked list. 10 | class ListNode: 11 | def __init__(self, val=0, next=None): 12 | self.val = val 13 | self.next = next 14 | 15 | 16 | class Solution: 17 | def oddEvenList(self, head: ListNode) -> ListNode: 18 | odd_head = ListNode() 19 | even_head = ListNode() 20 | 21 | q, oh, eh = head, odd_head, even_head 22 | idx = 1 23 | while q is not None: 24 | if idx % 2 == 1: 25 | oh.next = q 26 | oh = oh.next 27 | else: 28 | eh.next = q 29 | eh = eh.next 30 | 31 | # print(q.val) 32 | q = q.next 33 | idx = idx + 1 34 | 35 | oh.next = even_head.next 36 | eh.next = None 37 | return odd_head.next 38 | 39 | 40 | if __name__ == '__main__': 41 | a = [1, 2, 3, 4, 5] 42 | head = ListNode() 43 | hq = head 44 | for i in range(len(a) - 1): 45 | hq.val = a[i] 46 | hq.next = ListNode() 47 | hq = hq.next 48 | hq.val = a[-1] 49 | head_ = Solution().oddEvenList(head) 50 | print('ok') 51 | 52 | import time 53 | 54 | # time.sleep(10) 55 | while head_: 56 | print(head_.val) 57 | head_ = head_.next 58 | -------------------------------------------------------------------------------- /code/341. 扁平化嵌套列表迭代器.py: -------------------------------------------------------------------------------- 1 | # Author: BeiYu 2 | # Github: https://github.com/beiyuouo 3 | # Date : 2021/3/23 01:03 4 | # Description: 5 | 6 | __author__ = "BeiYu" 7 | 8 | 9 | # """ 10 | # This is the interface that allows for creating nested lists. 11 | # You should not implement it, or speculate about its implementation 12 | # """ 13 | class NestedInteger: 14 | def isInteger(self) -> bool: 15 | """ 16 | @return True if this NestedInteger holds a single integer, rather than a nested list. 17 | """ 18 | 19 | def getInteger(self) -> int: 20 | """ 21 | @return the single integer that this NestedInteger holds, if it holds a single integer 22 | Return None if this NestedInteger holds a nested list 23 | """ 24 | 25 | def getList(self) -> [NestedInteger]: 26 | """ 27 | @return the nested list that this NestedInteger holds, if it holds a nested list 28 | Return None if this NestedInteger holds a single integer 29 | """ 30 | 31 | 32 | class NestedIterator: 33 | def __init__(self, nestedList: [NestedInteger]): 34 | self.myList = [] 35 | self.pt = 0 36 | 37 | def _dfs(curList: [NestedInteger]): 38 | if curList.isInteger(): 39 | self.myList.append(curList.getInteger()) 40 | return 41 | 42 | for i in curList.getList(): 43 | _dfs(i) 44 | 45 | for i in nestedList: 46 | _dfs(i) 47 | 48 | def next(self) -> int: 49 | self.pt += 1 50 | return self.myList[self.pt - 1] 51 | 52 | def hasNext(self) -> bool: 53 | return self.pt < len(self.myList) 54 | 55 | # Your NestedIterator object will be instantiated and called as such: 56 | # i, v = NestedIterator(nestedList), [] 57 | # while i.hasNext(): v.append(i.next()) 58 | -------------------------------------------------------------------------------- /code/342. 4的幂.py: -------------------------------------------------------------------------------- 1 | # Author: BeiYu 2 | # Github: https://github.com/beiyuouo 3 | # Date : 2021/3/27 01:11 4 | # Description: 5 | 6 | __author__ = "BeiYu" 7 | 8 | import math 9 | 10 | 11 | class Solution: 12 | eps = 1e-6 13 | 14 | def isPowerOfFour(self, n: int) -> bool: 15 | if n <= 0: 16 | return False 17 | # print(math.log(n, 4)) 18 | _log = int(math.log(n, 4) + self.eps) 19 | return n == 4 ** _log 20 | -------------------------------------------------------------------------------- /code/344. 反转字符串.py: -------------------------------------------------------------------------------- 1 | # Author: BeiYu 2 | # Github: https://github.com/beiyuouo 3 | # Date : 2021/3/26 01:25 4 | # Description: 5 | 6 | __author__ = "BeiYu" 7 | 8 | from typing import List 9 | 10 | 11 | class Solution: 12 | def reverseString(self, s: List[str]) -> None: 13 | """ 14 | Do not return anything, modify s in-place instead. 15 | """ 16 | s.reverse() 17 | -------------------------------------------------------------------------------- /code/345. 反转字符串中的元音字母.py: -------------------------------------------------------------------------------- 1 | # Author: BeiYu 2 | # Github: https://github.com/beiyuouo 3 | # Date : 2021/3/26 01:28 4 | # Description: 5 | 6 | __author__ = "BeiYu" 7 | 8 | 9 | class Solution: 10 | def reverseVowels(self, s: str) -> str: 11 | l, r = 0, len(s) - 1 12 | vowels = ['a', 'e', 'i', 'o', 'u', 'A', 'E', 'I', 'O', 'U'] 13 | ss = [x for x in s] 14 | while l < r: 15 | while l < len(ss) and ss[l] not in vowels: 16 | l += 1 17 | while r >= 0 and ss[r] not in vowels: 18 | r -= 1 19 | if l < r and ss[l] in vowels and ss[r] in vowels: 20 | ss[l], ss[r] = ss[r], ss[l] 21 | l += 1 22 | r -= 1 23 | return "".join(ss) 24 | 25 | 26 | if __name__ == '__main__': 27 | print(Solution().reverseVowels("leetcode")) 28 | -------------------------------------------------------------------------------- /code/35. 搜索插入位置.py: -------------------------------------------------------------------------------- 1 | # Author: BeiYu 2 | # Github: https://github.com/beiyuouo 3 | # Date : 2021/3/31 01:44 4 | # Description: 5 | 6 | __author__ = "BeiYu" 7 | 8 | from typing import List 9 | 10 | 11 | class Solution: 12 | def searchInsert(self, nums: List[int], target: int) -> int: 13 | for i in range(len(nums)): 14 | if nums[i] == target: 15 | return i 16 | elif nums[i] > target: 17 | return i 18 | return len(nums) 19 | -------------------------------------------------------------------------------- /code/357. 计算各个位数不同的数字个数.py: -------------------------------------------------------------------------------- 1 | # Author: BeiYu 2 | # Github: https://github.com/beiyuouo 3 | # Date : 2021/3/27 01:16 4 | # Description: 5 | 6 | __author__ = "BeiYu" 7 | 8 | 9 | class Solution: 10 | def countNumbersWithUniqueDigits(self, n: int) -> int: 11 | if n == 0: 12 | return 1 13 | f = [0 for i in range(11)] 14 | f[0], f[1] = 0, 10 15 | 16 | def _P(_n: int) -> int: 17 | _res = 1 18 | for _i in range(1, _n + 1): 19 | _res *= _i 20 | return _res 21 | 22 | def _A(_n: int, _m: int) -> int: 23 | return _P(_n) // _P(_n - _m) 24 | 25 | def _C(_n: int, _m: int) -> int: 26 | return _P(_n) // _P(_n - _m) // _P(_m) 27 | 28 | for i in range(2, 11): 29 | f[i] = 9 * _A(9, i - 1) 30 | 31 | res = 0 32 | for i in range(min(n + 1, 11)): 33 | res += f[i] 34 | # print(f) 35 | return res 36 | 37 | 38 | if __name__ == '__main__': 39 | print(Solution().countNumbersWithUniqueDigits(2)) 40 | -------------------------------------------------------------------------------- /code/38. 外观数列.py: -------------------------------------------------------------------------------- 1 | # Author: BeiYu 2 | # Github: https://github.com/beiyuouo 3 | # Date : 2021/3/31 01:44 4 | # Description: 5 | 6 | __author__ = "BeiYu" 7 | 8 | 9 | class Solution: 10 | def countAndSay(self, n: int) -> str: 11 | if n == 1: 12 | return "1" 13 | desc_str = self.countAndSay(n - 1) 14 | desc = "" 15 | 16 | i, j = 0, 0 17 | while i < len(desc_str): 18 | j = i + 1 19 | while j < len(desc_str) and desc_str[i] == desc_str[j]: 20 | j += 1 21 | desc += str(j - i) + desc_str[i] 22 | i = j 23 | 24 | return desc 25 | -------------------------------------------------------------------------------- /code/392. 判断子序列.py: -------------------------------------------------------------------------------- 1 | # Author: BeiYu 2 | # Github: https://github.com/beiyuouo 3 | # Date : 2021/4/23 10:35 4 | # Description: 5 | 6 | __author__ = "BeiYu" 7 | 8 | 9 | class Solution: 10 | def isSubsequence(self, s: str, t: str) -> bool: 11 | cur = 0 12 | for i in range(len(t)): 13 | if cur < len(s) and s[cur] == t[i]: 14 | cur += 1 15 | return cur == len(s) 16 | -------------------------------------------------------------------------------- /code/404. 左叶子之和.py: -------------------------------------------------------------------------------- 1 | # Author: BeiYu 2 | # Github: https://github.com/beiyuouo 3 | # Date : 2021/4/24 01:37 4 | # Description: 5 | 6 | __author__ = "BeiYu" 7 | 8 | 9 | # Definition for a binary tree node. 10 | class TreeNode: 11 | def __init__(self, val=0, left=None, right=None): 12 | self.val = val 13 | self.left = left 14 | self.right = right 15 | 16 | 17 | class Solution: 18 | def sumOfLeftLeaves(self, root: TreeNode) -> int: 19 | global res 20 | res = 0 21 | 22 | def is_child(x: TreeNode): 23 | return x is not None and x.left is None and x.right is None 24 | 25 | def dfs(x: TreeNode): 26 | if x is None: return 27 | if x.left: dfs(x.left) 28 | if x.right: dfs(x.right) 29 | global res 30 | if is_child(x.left): res += x.left.val 31 | 32 | dfs(root) 33 | 34 | return res 35 | -------------------------------------------------------------------------------- /code/409. 最长回文串.py: -------------------------------------------------------------------------------- 1 | # Author: BeiYu 2 | # Github: https://github.com/beiyuouo 3 | # Date : 2021/4/28 00:45 4 | # Description: 5 | 6 | __author__ = "BeiYu" 7 | 8 | 9 | class Solution: 10 | def longestPalindrome(self, s: str) -> int: 11 | dic = {} 12 | for ch in s: 13 | if ch not in dic: 14 | dic[ch] = 0 15 | dic[ch] += 1 16 | 17 | res = 0 18 | flag = False 19 | for ch in dic.keys(): 20 | res += (dic[ch] // 2) * 2 21 | if dic[ch] % 2 == 1: 22 | flag = True 23 | 24 | return res + 1 if flag else res 25 | -------------------------------------------------------------------------------- /code/41. 缺失的第一个正数.py: -------------------------------------------------------------------------------- 1 | # Author: BeiYu 2 | # Github: https://github.com/beiyuouo 3 | # Date : 2021/4/15 00:59 4 | # Description: 5 | 6 | __author__ = "BeiYu" 7 | 8 | from typing import List 9 | 10 | 11 | class Solution: 12 | def firstMissingPositive(self, nums: List[int]) -> int: 13 | for i in range(len(nums)): 14 | while i + 1 != nums[i]: 15 | if nums[i] == nums[nums[i] - 1] or nums[i] < 0 or nums[i] > N: 16 | break 17 | 18 | t = nums[i] 19 | nums[i] = nums[t - 1] 20 | nums[t - 1] = t 21 | 22 | for i in range(len(nums)): 23 | if nums[i] != i + 1: 24 | return i + 1 25 | 26 | return -1 27 | -------------------------------------------------------------------------------- /code/412. Fizz Buzz.py: -------------------------------------------------------------------------------- 1 | # Author: BeiYu 2 | # Github: https://github.com/beiyuouo 3 | # Date : 2021/3/25 11:47 4 | # Description: 5 | 6 | __author__ = "BeiYu" 7 | 8 | from typing import List 9 | 10 | 11 | class Solution: 12 | def fizzBuzz(self, n: int) -> List[str]: 13 | res = [] 14 | for i in range(1, n + 1): 15 | if i % 3 == 0 and i % 5 == 0: 16 | res.append("FizzBuzz") 17 | elif i % 3 == 0: 18 | res.append("Fizz") 19 | elif i % 5 == 0: 20 | res.append("Buzz") 21 | else: 22 | res.append(str(i)) 23 | return res 24 | -------------------------------------------------------------------------------- /code/442. 数组中重复的数据.py: -------------------------------------------------------------------------------- 1 | # Author: BeiYu 2 | # Github: https://github.com/beiyuouo 3 | # Date : 2021/4/15 00:55 4 | # Description: 5 | 6 | __author__ = "BeiYu" 7 | 8 | from typing import List 9 | 10 | 11 | class Solution: 12 | def findDuplicates(self, nums: List[int]) -> List[int]: 13 | res = [] 14 | for i in range(len(nums)): 15 | while i + 1 != nums[i]: 16 | if nums[nums[i] - 1] == nums[i]: 17 | break 18 | t = nums[i] 19 | nums[i] = nums[t - 1] 20 | nums[t - 1] = t 21 | # print(nums) 22 | 23 | for i in range(len(nums)): 24 | if i + 1 != nums[i]: 25 | res.append(nums[i]) 26 | 27 | return res 28 | -------------------------------------------------------------------------------- /code/448. 找到所有数组中消失的数字.py: -------------------------------------------------------------------------------- 1 | # Author: BeiYu 2 | # Github: https://github.com/beiyuouo 3 | # Date : 2021/4/15 00:40 4 | # Description: 5 | 6 | __author__ = "BeiYu" 7 | 8 | from typing import List 9 | 10 | 11 | class Solution: 12 | def findDisappearedNumbers(self, nums: List[int]) -> List[int]: 13 | res = [] 14 | for i in range(len(nums)): 15 | while i + 1 != nums[i]: 16 | if nums[nums[i] - 1] == nums[i]: 17 | break 18 | t = nums[i] 19 | nums[i] = nums[t - 1] 20 | nums[t - 1] = t 21 | # print(nums) 22 | 23 | for i in range(len(nums)): 24 | if i + 1 != nums[i]: 25 | res.append(i + 1) 26 | 27 | return res 28 | -------------------------------------------------------------------------------- /code/461. 汉明距离.py: -------------------------------------------------------------------------------- 1 | # Author: BeiYu 2 | # Github: https://github.com/beiyuouo 3 | # Date : 2021/3/23 01:22 4 | # Description: 5 | 6 | __author__ = "BeiYu" 7 | 8 | 9 | class Solution: 10 | def hammingDistance(self, x: int, y: int) -> int: 11 | cnt = 0 12 | while x > 0 or y > 0: 13 | if x % 2 != y % 2: 14 | cnt += 1 15 | x, y = x//2, y//2 16 | return cnt 17 | -------------------------------------------------------------------------------- /code/5. 最长回文子串.py: -------------------------------------------------------------------------------- 1 | # Author: BeiYu 2 | # Github: https://github.com/beiyuouo 3 | # Date : 2021/3/23 01:35 4 | # Description: 这道题让我最恶心的一点就是卡Python常数,我服了。不能每次更新答案就更新答案的字符串,只记录起始和终止位置即可 5 | 6 | __author__ = "BeiYu" 7 | 8 | 9 | class Solution: 10 | def longestPalindrome(self, s: str) -> str: 11 | n = len(s) 12 | f = [[False for i in range(n)] for j in range(n)] 13 | 14 | ans = 1 15 | _start_idx = 0 16 | _end_idx = 0 17 | 18 | for i in range(n): 19 | f[i][i] = True 20 | 21 | for i in range(n - 1): 22 | f[i][i + 1] = s[i] == s[i + 1] 23 | if f[i][i + 1]: 24 | if 2 > ans: 25 | ans = 2 26 | _start_idx = i 27 | _end_idx = i + 1 28 | 29 | for _len in range(3, n + 1): 30 | for start_idx in range(n - _len + 1): 31 | end_idx = start_idx + _len - 1 32 | f[start_idx][end_idx] = f[start_idx + 1][end_idx - 1] and s[start_idx] == s[end_idx] 33 | if f[start_idx][end_idx]: 34 | if _len > ans: 35 | ans = _len 36 | _start_idx = start_idx 37 | _end_idx = end_idx 38 | 39 | return s[_start_idx: _end_idx + 1] 40 | -------------------------------------------------------------------------------- /code/53. 最大子序和.py: -------------------------------------------------------------------------------- 1 | # Author: BeiYu 2 | # Github: https://github.com/beiyuouo 3 | # Date : 2021/3/31 01:44 4 | # Description: 5 | 6 | __author__ = "BeiYu" 7 | 8 | from typing import List 9 | import math 10 | 11 | 12 | class Solution: 13 | def maxSubArray(self, nums: List[int]) -> int: 14 | prefix_sum = 0 15 | min_prefix_sum = 0 16 | ans_sum = - math.inf 17 | for i in range(len(nums)): 18 | prefix_sum += nums[i] 19 | ans_sum = max(ans_sum, prefix_sum - min_prefix_sum) 20 | if prefix_sum < min_prefix_sum: 21 | min_prefix_sum = prefix_sum 22 | 23 | return ans_sum 24 | -------------------------------------------------------------------------------- /code/58. 最后一个单词的长度.py: -------------------------------------------------------------------------------- 1 | # Author: BeiYu 2 | # Github: https://github.com/beiyuouo 3 | # Date : 2021/4/1 02:07 4 | # Description: 5 | 6 | __author__ = "BeiYu" 7 | 8 | 9 | class Solution: 10 | def lengthOfLastWord(self, s: str) -> int: 11 | return len(s.strip(" ").split(" ")[-1]) 12 | -------------------------------------------------------------------------------- /code/633. 平方数之和.py: -------------------------------------------------------------------------------- 1 | # Author: BeiYu 2 | # Github: https://github.com/beiyuouo 3 | # Date : 2021/4/28 01:02 4 | # Description: 5 | 6 | __author__ = "BeiYu" 7 | 8 | import math 9 | 10 | 11 | class Solution: 12 | def judgeSquareSum(self, c: int) -> bool: 13 | a = 0 14 | while 2 * (a ** 2) <= c: 15 | b = int(math.sqrt(c - a ** 2)) 16 | if a * a + b * b == c: 17 | return True 18 | a = a + 1 19 | return False 20 | -------------------------------------------------------------------------------- /code/66. 加一.py: -------------------------------------------------------------------------------- 1 | # Author: BeiYu 2 | # Github: https://github.com/beiyuouo 3 | # Date : 2021/4/1 02:07 4 | # Description: 5 | 6 | __author__ = "BeiYu" 7 | 8 | from typing import List 9 | 10 | 11 | class Solution: 12 | def plusOne(self, digits: List[int]) -> List[int]: 13 | return [int(ch) for ch in str(int("".join([str(x) for x in digits])) + 1)] 14 | -------------------------------------------------------------------------------- /code/67. 二进制求和.py: -------------------------------------------------------------------------------- 1 | # Author: BeiYu 2 | # Github: https://github.com/beiyuouo 3 | # Date : 2021/4/1 02:07 4 | # Description: 5 | 6 | __author__ = "BeiYu" 7 | 8 | 9 | class Solution: 10 | def addBinary(self, a: str, b: str) -> str: 11 | return bin(int(a, 2) + int(b, 2))[2:] 12 | -------------------------------------------------------------------------------- /code/69. x 的平方根.py: -------------------------------------------------------------------------------- 1 | # Author: BeiYu 2 | # Github: https://github.com/beiyuouo 3 | # Date : 2021/4/2 15:47 4 | # Description: 5 | 6 | __author__ = "BeiYu" 7 | 8 | 9 | class Solution: 10 | def mySqrt(self, x: int) -> int: 11 | import math 12 | eps = 1e-6 13 | return int(math.floor(math.sqrt(x) + eps)) 14 | -------------------------------------------------------------------------------- /code/697. 数组的度.py: -------------------------------------------------------------------------------- 1 | # Author: BeiYu 2 | # Github: https://github.com/beiyuouo 3 | # Date : 2021/4/13 20:41 4 | # Description: 5 | 6 | __author__ = "BeiYu" 7 | 8 | from typing import List 9 | 10 | 11 | class Solution: 12 | def findShortestSubArray(self, nums: List[int]) -> int: 13 | count = {} 14 | 15 | for idx, num in enumerate(nums): 16 | if num not in count.keys(): 17 | count[num] = [] 18 | count[num].append(idx) 19 | 20 | degree = 0 21 | res = len(nums) 22 | for key in count.keys(): 23 | if len(count[key]) > degree: 24 | degree = len(count[key]) 25 | res = count[key][-1] - count[key][0] + 1 26 | elif len(count[key]) == degree: 27 | res = min(res, count[key][-1] - count[key][0] + 1) 28 | 29 | return res 30 | -------------------------------------------------------------------------------- /code/7. 整数反转.py: -------------------------------------------------------------------------------- 1 | # Author: BeiYu 2 | # Github: https://github.com/beiyuouo 3 | # Date : 2021/3/22 12:29 4 | # Description: 5 | 6 | __author__ = "BeiYu" 7 | 8 | 9 | class Solution: 10 | def reverse(self, x: int) -> int: 11 | if x > 0: 12 | ans = int(str(x)[::-1]) 13 | else: 14 | ans = int('-' + str(abs(x))[::-1]) 15 | 16 | if x > 2 ** 31 - 1 or x < -2 ** 31 or ans > 2 ** 31 - 1 or ans < -2 ** 31: 17 | return 0 18 | else: 19 | return ans 20 | -------------------------------------------------------------------------------- /code/70. 爬楼梯.py: -------------------------------------------------------------------------------- 1 | # Author: BeiYu 2 | # Github: https://github.com/beiyuouo 3 | # Date : 2021/4/2 15:48 4 | # Description: 5 | 6 | __author__ = "BeiYu" 7 | 8 | 9 | class Solution: 10 | def climbStairs(self, n: int) -> int: 11 | 12 | f = [0 for x in range(n+1)] 13 | 14 | f[0] = 1 15 | f[1] = 1 16 | for i in range(2, n+1): 17 | f[i] = f[i-1] + f[i-2] 18 | 19 | return f[n] 20 | -------------------------------------------------------------------------------- /code/724. 寻找数组的中心下标.py: -------------------------------------------------------------------------------- 1 | # Author: BeiYu 2 | # Github: https://github.com/beiyuouo 3 | # Date : 2021/4/16 13:56 4 | # Description: 5 | 6 | __author__ = "BeiYu" 7 | 8 | from typing import List 9 | 10 | 11 | class Solution: 12 | def pivotIndex(self, nums: List[int]) -> int: 13 | pre_sum = [] 14 | for i in range(len(nums)): 15 | if i > 0: 16 | pre_sum.append(pre_sum[-1] + nums[i]) 17 | else: 18 | pre_sum.append(nums[i]) 19 | 20 | def get_pre_sum(x: int) -> int: 21 | if x < 0: 22 | return 0 23 | if x >= len(nums): 24 | return pre_sum[-1] 25 | return pre_sum[x] 26 | 27 | for i in range(len(nums)): 28 | if get_pre_sum(i - 1) == get_pre_sum(len(nums) - 1) - get_pre_sum(i): 29 | return i 30 | return -1 31 | -------------------------------------------------------------------------------- /code/73. 矩阵置零.py: -------------------------------------------------------------------------------- 1 | # Author: BeiYu 2 | # Github: https://github.com/beiyuouo 3 | # Date : 2021/4/13 20:42 4 | # Description: 5 | 6 | __author__ = "BeiYu" 7 | 8 | from typing import List 9 | 10 | 11 | class Solution: 12 | def setZeroes(self, matrix: List[List[int]]) -> None: 13 | """ 14 | Do not return anything, modify matrix in-place instead. 15 | """ 16 | ban_row = {} 17 | ban_col = {} 18 | 19 | for i in range(len(matrix)): 20 | for j in range(len(matrix[i])): 21 | if matrix[i][j] == 0: 22 | ban_row[i] = 1 23 | ban_col[j] = 1 24 | 25 | for i in range(len(matrix)): 26 | for j in range(len(matrix[i])): 27 | if i in ban_row.keys() or j in ban_col.keys(): 28 | matrix[i][j] = 0 29 | -------------------------------------------------------------------------------- /code/771. 宝石与石头.py: -------------------------------------------------------------------------------- 1 | # Author: BeiYu 2 | # Github: https://github.com/beiyuouo 3 | # Date : 2021/3/22 13:40 4 | # Description: 5 | 6 | __author__ = "BeiYu" 7 | 8 | 9 | class Solution: 10 | def numJewelsInStones(self, jewels: str, stones: str) -> int: 11 | cnt = 0 12 | for Ji in jewels: 13 | for Si in stones: 14 | if Ji == Si: 15 | cnt += 1 16 | return cnt 17 | -------------------------------------------------------------------------------- /code/83. 删除排序链表中的重复元素.py: -------------------------------------------------------------------------------- 1 | # Author: BeiYu 2 | # Github: https://github.com/beiyuouo 3 | # Date : 2021/4/2 15:50 4 | # Description: 5 | 6 | __author__ = "BeiYu" 7 | 8 | 9 | # Definition for singly-linked list. 10 | class ListNode: 11 | def __init__(self, val=0, next=None): 12 | self.val = val 13 | self.next = next 14 | 15 | 16 | class Solution: 17 | def deleteDuplicates(self, head: ListNode) -> ListNode: 18 | q = head 19 | while q: 20 | while q.next and q.next.val == q.val: 21 | q.next = q.next.next 22 | 23 | q = q.next 24 | 25 | return head 26 | -------------------------------------------------------------------------------- /code/832. 翻转图像.py: -------------------------------------------------------------------------------- 1 | # Author: BeiYu 2 | # Github: https://github.com/beiyuouo 3 | # Date : 2021/4/12 01:18 4 | # Description: 5 | 6 | __author__ = "BeiYu" 7 | 8 | from typing import List 9 | 10 | 11 | class Solution: 12 | def flipAndInvertImage(self, image: List[List[int]]) -> List[List[int]]: 13 | for i in range(len(image)): 14 | image[i] = image[i][::-1] 15 | for j in range(len(image[i])): 16 | image[i][j] = image[i][j] ^ 1 17 | 18 | return image 19 | -------------------------------------------------------------------------------- /code/867. 转置矩阵.py: -------------------------------------------------------------------------------- 1 | # Author: BeiYu 2 | # Github: https://github.com/beiyuouo 3 | # Date : 2021/4/17 01:41 4 | # Description: 5 | 6 | __author__ = "BeiYu" 7 | 8 | from typing import List 9 | 10 | 11 | class Solution: 12 | def transpose(self, matrix: List[List[int]]) -> List[List[int]]: 13 | n = len(matrix) 14 | m = len(matrix[0]) 15 | 16 | _matrix = [[0 for j in range(n)] for i in range(m)] 17 | 18 | for i in range(m): 19 | for j in range(n): 20 | _matrix[i][j] = matrix[j][i] 21 | 22 | return _matrix 23 | -------------------------------------------------------------------------------- /code/88. 合并两个有序数组.py: -------------------------------------------------------------------------------- 1 | # Author: BeiYu 2 | # Github: https://github.com/beiyuouo 3 | # Date : 2021/4/3 16:03 4 | # Description: 5 | 6 | __author__ = "BeiYu" 7 | 8 | from typing import List 9 | 10 | 11 | class Solution: 12 | def merge(self, nums1: List[int], m: int, nums2: List[int], n: int) -> None: 13 | """ 14 | Do not return anything, modify nums1 in-place instead. 15 | """ 16 | 17 | while len(nums1) > m: 18 | nums1.pop() 19 | 20 | nums1.extend(nums2) 21 | nums1.sort() 22 | -------------------------------------------------------------------------------- /code/9. 回文数.py: -------------------------------------------------------------------------------- 1 | # Author: BeiYu 2 | # Github: https://github.com/beiyuouo 3 | # Date : 2021/3/22 12:29 4 | # Description: 5 | 6 | __author__ = "BeiYu" 7 | 8 | 9 | class Solution: 10 | def isPalindrome(self, x: int) -> bool: 11 | return str(x) == str(x)[::-1] 12 | -------------------------------------------------------------------------------- /code/LCP 01. 猜数字.py: -------------------------------------------------------------------------------- 1 | # Author: BeiYu 2 | # Github: https://github.com/beiyuouo 3 | # Date : 2021/3/14 13:54 4 | # Description: 5 | 6 | __author__ = "BeiYu" 7 | 8 | from typing import List 9 | 10 | 11 | class Solution: 12 | def game(self, guess: List[int], answer: List[int]) -> int: 13 | result = [1 if guess[i] == answer[i] else 0 for i in range(len(guess))] 14 | return sum(result) 15 | -------------------------------------------------------------------------------- /code/LCP 06. 拿硬币.py: -------------------------------------------------------------------------------- 1 | # Author: BeiYu 2 | # Github: https://github.com/beiyuouo 3 | # Date : 2021/3/15 14:12 4 | # Description: 5 | 6 | __author__ = "BeiYu" 7 | 8 | from typing import List 9 | import math 10 | 11 | 12 | class Solution: 13 | def minCount(self, coins: List[int]) -> int: 14 | res = 0 15 | for coin in coins: 16 | res += math.ceil(coin / 2) 17 | return res 18 | -------------------------------------------------------------------------------- /code/LCP 17. 速算机器人.py: -------------------------------------------------------------------------------- 1 | # Author: BeiYu 2 | # Github: https://github.com/beiyuouo 3 | # Date : 2021/3/23 01:20 4 | # Description: 5 | 6 | __author__ = "BeiYu" 7 | 8 | 9 | class Solution: 10 | def calculate(self, s: str) -> int: 11 | x, y = 1, 0 12 | for ch in s: 13 | if ch == 'A': 14 | x = 2 * x + y 15 | else: 16 | y = 2 * y + x 17 | return x + y 18 | -------------------------------------------------------------------------------- /code/剑指 Offer 03. 数组中重复的数字.py: -------------------------------------------------------------------------------- 1 | # Author: BeiYu 2 | # Github: https://github.com/beiyuouo 3 | # Date : 2021/4/27 01:37 4 | # Description: 5 | 6 | __author__ = "BeiYu" 7 | 8 | from typing import List 9 | 10 | 11 | class Solution: 12 | def findRepeatNumber(self, nums: List[int]) -> int: 13 | dic = {} 14 | for i in range(len(nums)): 15 | if nums[i] in dic.keys(): 16 | return nums[i] 17 | dic[nums[i]] = 1 18 | 19 | -------------------------------------------------------------------------------- /code/剑指 Offer 05. 替换空格.py: -------------------------------------------------------------------------------- 1 | # Author: BeiYu 2 | # Github: https://github.com/beiyuouo 3 | # Date : 2021/4/28 01:04 4 | # Description: 5 | 6 | __author__ = "BeiYu" 7 | 8 | 9 | class Solution: 10 | def replaceSpace(self, s: str) -> str: 11 | return s.replace(' ', '%20') 12 | -------------------------------------------------------------------------------- /code/剑指 Offer 10- I. 斐波那契数列.py: -------------------------------------------------------------------------------- 1 | # Author: BeiYu 2 | # Github: https://github.com/beiyuouo 3 | # Date : 2021/4/28 00:54 4 | # Description: 5 | 6 | __author__ = "BeiYu" 7 | 8 | 9 | class Solution: 10 | def fib(self, n: int) -> int: 11 | f = [0, 1] 12 | for i in range(n): 13 | f.append((f[-1] + f[-2]) % 1000000007) 14 | 15 | return f[n] 16 | -------------------------------------------------------------------------------- /code/剑指 Offer 11. 旋转数组的最小数字.py: -------------------------------------------------------------------------------- 1 | # Author: BeiYu 2 | # Github: https://github.com/beiyuouo 3 | # Date : 2021/4/28 01:08 4 | # Description: 5 | 6 | __author__ = "BeiYu" 7 | 8 | from typing import List 9 | 10 | 11 | class Solution: 12 | def minArray(self, numbers: List[int]) -> int: 13 | return min(numbers) 14 | -------------------------------------------------------------------------------- /code/剑指 Offer 17. 打印从1到最大的n位数.py: -------------------------------------------------------------------------------- 1 | # Author: BeiYu 2 | # Github: https://github.com/beiyuouo 3 | # Date : 2021/4/17 01:39 4 | # Description: 5 | 6 | __author__ = "BeiYu" 7 | 8 | from typing import List 9 | 10 | 11 | class Solution: 12 | def printNumbers(self, n: int) -> List[int]: 13 | res = [] 14 | itr = 1 15 | while True: 16 | if len(str(itr)) > n: 17 | break 18 | res.append(itr) 19 | itr += 1 20 | 21 | return res 22 | -------------------------------------------------------------------------------- /code/剑指 Offer 39. 数组中出现次数超过一半的数字.py: -------------------------------------------------------------------------------- 1 | # Author: BeiYu 2 | # Github: https://github.com/beiyuouo 3 | # Date : 2021/4/13 20:42 4 | # Description: 5 | 6 | __author__ = "BeiYu" 7 | 8 | from typing import List 9 | 10 | 11 | class Solution: 12 | def majorityElement(self, nums: List[int]) -> int: 13 | count = 1 14 | res = nums[0] 15 | 16 | for i in range(1, len(nums)): 17 | if nums[i] == res: 18 | count += 1 19 | else: 20 | count -= 1 21 | if count == 0: 22 | res = nums[i] 23 | count = 1 24 | 25 | return res 26 | -------------------------------------------------------------------------------- /code/剑指 Offer 50. 第一个只出现一次的字符.py: -------------------------------------------------------------------------------- 1 | # Author: BeiYu 2 | # Github: https://github.com/beiyuouo 3 | # Date : 2021/4/16 13:39 4 | # Description: 5 | 6 | __author__ = "BeiYu" 7 | 8 | 9 | class Solution: 10 | def firstUniqChar(self, s: str) -> str: 11 | dic = {} 12 | for ch in s: 13 | if ch not in dic.keys(): 14 | dic[ch] = 0 15 | dic[ch] += 1 16 | 17 | for ch in s: 18 | if dic[ch] == 1: 19 | return ch 20 | return " " 21 | -------------------------------------------------------------------------------- /code/剑指 Offer 53 - II. 0~n-1中缺失的数字.py: -------------------------------------------------------------------------------- 1 | # Author: BeiYu 2 | # Github: https://github.com/beiyuouo 3 | # Date : 2021/4/25 09:50 4 | # Description: 5 | 6 | __author__ = "BeiYu" 7 | 8 | from typing import List 9 | 10 | 11 | class Solution: 12 | def missingNumber(self, nums: List[int]) -> int: 13 | xor_arr, xor_all = 0, 0 14 | for i in range(len(nums)): 15 | xor_arr = xor_arr ^ nums[i] 16 | for i in range(len(nums) + 1): 17 | xor_all = xor_all ^ i 18 | return xor_all ^ xor_arr 19 | -------------------------------------------------------------------------------- /code/剑指 Offer 58 - II. 左旋转字符串.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def reverseLeftWords(self, s: str, n: int) -> str: 3 | return s[n:] + s[:n] 4 | -------------------------------------------------------------------------------- /code/面试题 01.01. 判定字符是否唯一.py: -------------------------------------------------------------------------------- 1 | # Author: BeiYu 2 | # Github: https://github.com/beiyuouo 3 | # Date : 2021/4/28 00:49 4 | # Description: 5 | 6 | __author__ = "BeiYu" 7 | 8 | 9 | class Solution: 10 | def isUnique(self, astr: str) -> bool: 11 | import numpy as np 12 | return np.unique(list(astr)).shape[0] == len(astr) 13 | -------------------------------------------------------------------------------- /code/面试题 01.02. 判定是否互为字符重排.py: -------------------------------------------------------------------------------- 1 | # Author: BeiYu 2 | # Github: https://github.com/beiyuouo 3 | # Date : 2021/4/12 01:16 4 | # Description: 5 | 6 | __author__ = "BeiYu" 7 | 8 | 9 | class Solution: 10 | def CheckPermutation(self, s1: str, s2: str) -> bool: 11 | arr1 = [x for x in s1] 12 | arr2 = [x for x in s2] 13 | arr1.sort() 14 | arr2.sort() 15 | return ''.join(arr1) == ''.join(arr2) 16 | -------------------------------------------------------------------------------- /code/面试题 02.03. 删除中间节点.py: -------------------------------------------------------------------------------- 1 | # Author: BeiYu 2 | # Github: https://github.com/beiyuouo 3 | # Date : 2021/3/22 12:27 4 | # Description: 5 | 6 | __author__ = "BeiYu" 7 | 8 | 9 | # Definition for singly-linked list. 10 | # class ListNode: 11 | # def __init__(self, x): 12 | # self.val = x 13 | # self.next = None 14 | 15 | class Solution: 16 | def deleteNode(self, node): 17 | """ 18 | :type node: ListNode 19 | :rtype: void Do not return anything, modify node in-place instead. 20 | """ 21 | node.val = node.next.val 22 | node.next = node.next.next 23 | -------------------------------------------------------------------------------- /code/面试题 10.01. 合并排序的数组.py: -------------------------------------------------------------------------------- 1 | # Author: BeiYu 2 | # Github: https://github.com/beiyuouo 3 | # Date : 2021/4/27 01:34 4 | # Description: 5 | 6 | __author__ = "BeiYu" 7 | 8 | from typing import List 9 | 10 | 11 | class Solution: 12 | def merge(self, A: List[int], m: int, B: List[int], n: int) -> None: 13 | """ 14 | Do not return anything, modify A in-place instead. 15 | """ 16 | for i in range(n): 17 | A[m + i] = B[i] 18 | 19 | sorted(A) 20 | --------------------------------------------------------------------------------