/images/avatar.png

vllbc

thread

import threading import time 简单的创建 def run(n): print("task", n) time.sleep(1) print('2s') time.sleep(1) print('1s') time.sleep(1) print('0s') time.sleep(1) if __name__ == '__main__': t1 = threading.Thread(target=run, args=("t1",)) t2 = threading.Thread(target=run, args=("t2",)) t1.start() t2.start() 通过类创建 class MyThread(threading.Thread): def __init__(self, n): super(MyThread, self).__init__() # 重构run函数必须要写 self.n = n def run(self): print("task", self.n) time.sleep(1) print('2s') time.sleep(1) print('1s') time.sleep(1)

丑数系列

丑数系列 1.丑数 题目: https://leetcode-cn.com/problems/ugly-number/ 思路: 就是让这个数字不断地除以2.3.5 如果最后变成了1 就说明是个丑数 代码: class Solution: def isUgly(self, num: int) -> bool: if num<=-231 or num>=231-1: return False while num >1: if num %2

零钱兑换

零钱兑换 https://leetcode-cn.com/problems/coin-change/ 以我目前的水平做出来有点吃力,看了思路才做出来 class Solution: def coinChange(self, coins: List[int], amount: int) -> int: dp = [float('inf')] * (amount + 1) dp[0] = 0 for i in range(amount+1): for coin in coins: # if i >= coin: dp[i] = min(dp[i],dp[i-coin]+1) return -1 if (dp[-1] == float("inf"))

去除重复字母

去除重复字母 一开始看到题目感觉挺简单的,没想到对现在的我挺有难度。。 https://leetcode-cn.com/problems/remove-duplicate-letters/ #1 class Solution: def removeDuplicateLetters(s: str): res = "" while s: #用递归也可以 loc = min(map(s.rindex,s)) #s.rindex是返回列表