上一页 1 ··· 5 6 7 8 9 10 11 12 13 ··· 16 下一页
摘要: from typing import List# 这道题比较容易,遍历一遍k + 1就好了,# 可以算出所有的结果,但是会有重复值,因此需要将重复值排除# 同时避免超市class Solution: def divingBoard(self, shorter: int, longer: int, k 阅读全文
posted @ 2020-07-14 15:42 月为暮 阅读(180) 评论(0) 推荐(0) 编辑
摘要: from typing import List# 八皇后问题,用递归的方法来写。class Solution: def solveNQueens(self, n: int) -> List[List[str]]: # 如果n < 1直接返回空列表 if n < 1:return [] # 定义变量用 阅读全文
posted @ 2020-07-13 19:51 月为暮 阅读(230) 评论(0) 推荐(0) 编辑
摘要: from typing import Listclass Solution: def findSubstring(self, s: str, words: List[str]) -> List[int]: # 导入计数类 from collections import Counter # 如果s和w 阅读全文
posted @ 2020-07-13 19:15 月为暮 阅读(169) 评论(0) 推荐(0) 编辑
摘要: from typing import Listclass Solution: def findMedianSortedArrays(self, nums1: List[int], nums2: List[int]) -> float: # 这样写可以不用判断两个数组和为奇数和偶数的情况 index1 阅读全文
posted @ 2020-07-06 10:34 月为暮 阅读(217) 评论(0) 推荐(0) 编辑
摘要: class Solution: def strStr(self, haystack: str, needle: str) -> int: # 判断needle是否为NOne或者为空字符串 if not needle or len(needle) == 0: return 0 # 定义两个变量,用来接 阅读全文
posted @ 2020-07-06 09:55 月为暮 阅读(211) 评论(0) 推荐(0) 编辑
摘要: # 利用双指针,一次遍历,求出结果class Solution: def isPalindrome(self, s: str) -> bool: # 定义变量,接收字符串的长度 length = len(s) # 长度小于等于1直接返回真 if length <= 1:return True # 定 阅读全文
posted @ 2020-07-04 21:02 月为暮 阅读(174) 评论(0) 推荐(0) 编辑
摘要: # Definition for a binary tree node.class TreeNode: def __init__(self, x): self.val = x self.left = None self.right = Nonea = TreeNode(1)b = TreeNode( 阅读全文
posted @ 2020-07-03 20:24 月为暮 阅读(256) 评论(0) 推荐(0) 编辑
摘要: from typing import Listclass Solution: def maxProfit(self, prices: List[int]) -> int: length = len(prices) if length <= 1:return 0 dp=[ [[0,0,0],[0,0, 阅读全文
posted @ 2020-07-02 16:29 月为暮 阅读(300) 评论(0) 推荐(0) 编辑
摘要: # 爬取豆瓣最受欢迎的250部电影,并写入Excel表格中import requests,xlwtfrom bs4 import BeautifulSoup# 请求豆瓣网站,获取网页源码def request_douban(url): try : # 请求url headers = {"User-A 阅读全文
posted @ 2020-07-02 13:40 月为暮 阅读(306) 评论(0) 推荐(0) 编辑
摘要: # import requests,re,json# # 定义一个函数用来请求当当网的网页信息# def request_dangdang(url):# try:# # 使用get请求# response = requests.get(url)# # 判断返回的状态码是否为200# if respo 阅读全文
posted @ 2020-07-01 21:00 月为暮 阅读(401) 评论(0) 推荐(1) 编辑
上一页 1 ··· 5 6 7 8 9 10 11 12 13 ··· 16 下一页