摘要: 1. 题目描述 2. 代码 1 class Solution: 2 def reverseString(self, s: 'List[str]') -> None: 3 """ 4 Do not return anything, modify s in-place instead. 5 """ 6 阅读全文
posted @ 2020-10-16 15:19 vv_869 阅读(66) 评论(0) 推荐(0) 编辑
摘要: 1. 题目描述 2. 代码 1 class Solution: 2 def removeDuplicates(self, nums: 'List[int]') -> int: 3 prevalue = 0 4 n = len(nums) 5 count = 0 6 i,j = 0,0 7 while 阅读全文
posted @ 2020-10-15 10:22 vv_869 阅读(96) 评论(0) 推荐(0) 编辑
摘要: 1. 题目描述 2. 代码 1 class Solution: 2 def findContentChildren(self, g: 'List[int]', s: 'List[int]') -> int: 3 g.sort()#对g排序 4 s.sort()#对s排序 5 a, b = 0, 0# 阅读全文
posted @ 2020-10-14 17:30 vv_869 阅读(118) 评论(0) 推荐(0) 编辑
摘要: 1. 题目描述 2. 代码 1 class Solution: 2 def maxProfit(self, prices: 'List[int]') -> int: 3 n = len(prices) 4 sums = 0 5 for i in range(1,n): 6 if prices[i] 阅读全文
posted @ 2020-10-13 16:34 vv_869 阅读(62) 评论(0) 推荐(0) 编辑
摘要: 1. 题目描述 2. 代码 1 import collections 2 3 class Solution: 4 def firstUniqChar(self, s: str) -> int: 5 dic = collections.OrderedDict()#有序字典 6 for i in ran 阅读全文
posted @ 2020-10-12 15:52 vv_869 阅读(90) 评论(0) 推荐(0) 编辑
摘要: 1. 题目描述 2. 代码 import collections class Solution: def intersect(self, nums1: 'List[int]', nums2: 'List[int]') -> 'List[int]': result = [] c1 = collecti 阅读全文
posted @ 2020-10-12 10:04 vv_869 阅读(82) 评论(0) 推荐(0) 编辑
摘要: 1. 题目描述 异位符指字母相同, 但次序不同. 2. 代码 1 class Solution: 2 def isAnagram(self, s: str, t: str) -> bool: 3 return sorted(s) == sorted(t) 思路: 利用sorted()进行排序, 然后 阅读全文
posted @ 2020-10-11 09:46 vv_869 阅读(120) 评论(0) 推荐(0) 编辑
摘要: 1. 题目描述 2.代码 1 class Solution: 2 def containsDuplicate(self, nums: List[int]) -> bool: 3 dic = {} 4 for n in nums: 5 if n not in dic: 6 dic[n] = 1 7 e 阅读全文
posted @ 2020-10-10 10:09 vv_869 阅读(116) 评论(0) 推荐(0) 编辑
摘要: 1. 题目描述 2. 代码 1 class Solution: 2 def findDisappearedNumbers(self, nums: 'List[int]') -> 'List[int]': 3 dic = {} 4 maxvalue = len(nums) 5 result = [] 阅读全文
posted @ 2020-10-10 09:50 vv_869 阅读(149) 评论(0) 推荐(0) 编辑
摘要: 1. 题目描述 2. 代码 1 class Solution: 2 def majorityElement(self, nums: 'List[int]') -> int: 3 dic = {}#定义一个字典,key是数字,value是出现次数 4 length = len(nums)#计算列表的长 阅读全文
posted @ 2020-10-09 16:23 vv_869 阅读(123) 评论(0) 推荐(0) 编辑