leecode刷题
涉及初级算法、中级算法、高级算法的leecode题目python代码
LaiYoung1022
大数据系统
数据分析与挖掘
服务端开发
python使用
机器学习
深度学习
展开
-
【leecode刷题】中级算法-其他
1、 逆波兰表达式求值class Solution(object): def evalRPN(self, tokens): """ :type tokens: List[str] :rtype: int """ class Stack: def __init__(self): self.items = [] def isEmpty(se原创 2020-09-12 18:18:47 · 168 阅读 · 0 评论 -
【leecode刷题】中级算法-数学
1、快乐树class Solution(object): def isHappy(self, n): """ :type n: int :rtype: bool """ # def cal(n): # if n==1: # return True # n = sum([int(math.pow(int(i),2)) for i in st原创 2020-09-12 18:15:17 · 187 阅读 · 0 评论 -
【leecode刷题】中级算法-数组和字符串
1、三数之和class Solution(object): def threeSum(self, nums): """ :type nums: List[int] :rtype: List[List[int]] """ # import itertools # import operator # # product 笛卡尔积 (有放回抽样排列) # # permutations 排列原创 2020-09-12 18:08:26 · 162 阅读 · 0 评论 -
【leecode刷题】初级算法-树
1、二叉树的最大深度class Solution(object): def maxDepth(self, root): """ :type root: TreeNode :rtype: int """ def height(root): if root == None: return 0 else: ret原创 2020-09-11 11:26:42 · 221 阅读 · 0 评论 -
【leecode刷题】初级算法-数组
1、删除排序数组中的重复项class Solution(object): def removeDuplicates(self, nums): """ :type nums: List[int] :rtype: int """ if len(nums)==0: return 0 else: i = 0 for j in range(l原创 2020-08-31 00:13:15 · 202 阅读 · 0 评论 -
【leecode刷题】初级算法-链表
1、删除链表中的节点class Solution(object): def deleteNode(self, node): """ :type node: ListNode :rtype: void Do not return anything, modify node in-place instead. """ node.val = node.next.val node.next = node.nex原创 2020-08-31 00:13:56 · 187 阅读 · 0 评论 -
【leecode刷题】初级算法-字符串
1、反转字符串class Solution(object): def reverseString(self, s): """ :type s: List[str] :rtype: None Do not return anything, modify s in-place instead. """ result = [] for i in range(len(s)): resul原创 2020-08-31 00:13:39 · 232 阅读 · 0 评论 -
【leecode刷题】初级算法-动态规划
1、爬楼梯原创 2020-09-04 11:19:10 · 224 阅读 · 0 评论 -
【leecode刷题】初级算法-其他
1、位1的个数class Solution(object): def hammingWeight(self, n): """ :type n: int :rtype: int """ count = 0 for i in '{0:032b}'.format(n): if i=="1": count = count+1 return原创 2020-09-04 09:00:06 · 229 阅读 · 0 评论 -
【leecode刷题】初级算法-设计问题
1、打乱数组class Solution: def __init__(self, nums): self.array = nums self.original = list(nums) def reset(self): self.array = self.original self.original = list(self.original) return self.array def shuff原创 2020-09-03 23:48:43 · 188 阅读 · 0 评论 -
【leecode刷题】初级算法-数学
1、Fizz Buzzclass Solution(object): def fizzBuzz(self, n): """ :type n: int :rtype: List[str] """ result = [] for i in range(1,n+1): if i%3 == 0 and i%5 == 0: result.append("F原创 2020-09-03 23:45:38 · 217 阅读 · 0 评论 -
【leecode刷题】初级算法-排序和搜索
1、合并两个有序数组class Solution(object): def merge(self, nums1, m, nums2, n): """ :type nums1: List[int] :type m: int :type nums2: List[int] :type n: int :rtype: None Do not return anything, modify nums1 in-place ins原创 2020-09-03 22:28:47 · 154 阅读 · 0 评论