上一页 1 ··· 3 4 5 6 7
摘要: # dfs的遍历 class Solution: def generateParenthesis(self, n: int) -> List[str]: if n <= 0: return [] # 特例判断 res = [] #设置返回列表 def dfs(paths, left, right): 阅读全文
posted @ 2022-07-12 16:52 是冰美式诶 阅读(30) 评论(0) 推荐(0)
摘要: #递归解法 class Solution: def mergeTwoLists(self, list1: Optional[ListNode], list2: Optional[ListNode]) -> Optional[ListNode]: if not list1: return list2# 阅读全文
posted @ 2022-07-12 15:35 是冰美式诶 阅读(68) 评论(0) 推荐(0)
摘要: import numpy as np import pandas as pd import matplotlib.pyplot as plt import seaborn as sns import datetime as dt import warnings warnings.filterwarn 阅读全文
posted @ 2022-07-11 19:47 是冰美式诶 阅读(152) 评论(0) 推荐(0)
摘要: #利用栈的特性,先进后处,刚好进行比较,{[()]}分别进行比较 class Solution: def isValid(self, s: str) -> bool: stk = [] for c in s: # 如果c是 ({[ 则入栈 if c in ['(','[','{']: stk.app 阅读全文
posted @ 2022-07-11 17:47 是冰美式诶 阅读(35) 评论(0) 推荐(0)
摘要: #循环迭代 # Definition for singly-linked list. # class ListNode: # def __init__(self, val=0, next=None): # self.val = val # self.next = next class Solutio 阅读全文
posted @ 2022-07-11 16:15 是冰美式诶 阅读(32) 评论(0) 推荐(0)
摘要: #三数之和双指针循环外再加一个循环,但有些细节还是在里面的,需注意 def fourSum(self, nums: List[int], target: int) -> List[List[int]]: res = [] #设置空列表做返回值 if len(nums)<4 : return res 阅读全文
posted @ 2022-07-11 15:01 是冰美式诶 阅读(25) 评论(0) 推荐(0)
摘要: # 本次采用KNN算法进行解析 import numpy as np import pandas as pd import matplotlib.pyplot as plt import warnings warnings.filterwarnings('ignore') #用于忽略由于版本更新等不 阅读全文
posted @ 2022-07-10 21:00 是冰美式诶 阅读(407) 评论(0) 推荐(0)
摘要: #dfs(深度优先遍历) #将数字转为字典格式 #定义dfs函数(本质上回溯问题),遍历dic[digit]返回值为dfs()函数,达到遍历的目的 #ps:由于存在空字符串的情况,必须设置加入条件!='' def letterCombinations(self, digits: str) -> Li 阅读全文
posted @ 2022-07-10 17:43 是冰美式诶 阅读(94) 评论(0) 推荐(0)
摘要: #暴力解法,直接三重循环 def threeSumClosest(self, nums: List[int], target: int) -> int: sub = 999999999999 sum = 0 for i in range(len(nums)): for j in range(i+1, 阅读全文
posted @ 2022-07-10 17:42 是冰美式诶 阅读(36) 评论(0) 推荐(0)
摘要: #双指针,注意排除重复值,比如[2,2]那么指针就要往前或者后移 def threeSum(self, nums: [int]) -> [[int]]: nums.sort()#从小到大排序 res, k = [], 0 for k in range(len(nums) - 2): if nums[ 阅读全文
posted @ 2022-07-10 17:40 是冰美式诶 阅读(31) 评论(0) 推荐(0)
上一页 1 ··· 3 4 5 6 7