随笔分类 - leetcode
摘要:题目描述: 自己的提交: class Solution: def processQueries(self, queries: List[int], m: int) -> List[int]: l = [i for i in range(1,m+1)] ans = [] for i in querie
阅读全文
摘要:题目描述: 自己的提交: class Solution: def stringMatching(self, words: List[str]) -> List[str]: def strStr(haystack: str, needle: str) -> int: if not needle:ret
阅读全文
摘要:javaO(N) /** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * ListNode(int x) { val = x; } * } */ class So
阅读全文
摘要:题目描述: 第一次提交: class Solution: def cuttingRope(self, n: int) -> int: ans = 0 for m in range(2,max(n//2,3)): j = 1 a = n//m b = n%m for _ in range(b): j
阅读全文
摘要:题目描述: 方法一:dfs/bfs class Solution: def movingCount(self, m: int, n: int, k: int) -> int: def digitsum(n): ans = 0 while n: ans += n %10 n//=10 return a
阅读全文
摘要:题目描述: 方法:从后向前dp class Solution(object): def stoneGameIII(self, A): n = len(A) dp = [-float('inf')] * n for i in range(n-1,-1,-1): dp[i] = max(dp[i], s
阅读全文
摘要:题目描述: 第一次提交 python: class Solution: def longestDiverseString(self, a: int, b: int, c: int) -> str: res = "" l = [["a", a], ["b", b], ["c", c]] l.sort(
阅读全文
摘要:题目描述: 排序加后缀和 class Solution: def maxSatisfaction(self, satisfaction: List[int]) -> int: satisfaction.sort() t_s = 0 res = 0 for i in satisfaction[::-1
阅读全文
摘要:题目描述: 统计字符奇偶次数即可 class Solution: def canConstruct(self, s: str, k: int) -> bool: if k > len(s): return False c = collections.Counter(s) o = sum(i % 2
阅读全文
摘要:题目描述: class Solution: def checkOverlap(self, radius: int, x_center: int, y_center: int, x1: int, y1: int, x2: int, y2: int) -> bool: a = max(0, x1 - x
阅读全文
摘要:题目描述: 方法一:java class Solution { public String replaceSpace(String s) { StringBuilder res = new StringBuilder(); for(Character c: s.toCharArray()){ if(
阅读全文
摘要:解法一:O(MN)O(MN))Java版 class Solution { public void gameOfLife(int[][] board) { int [] neighbors = {0,1,-1}; int rows = board.length; int cols = board[0
阅读全文
摘要:题目描述: 方法一:pythonO(N)O(1) class Solution: def maxDepthAfterSplit(self, seq: str) -> List[int]: d = 0 ans = [] for s in seq: if s == "(": d += 1 ans.app
阅读全文
摘要:恢复内容开始 题目描述:给定一个数组,返回排序后的数组。 python 归并排序: class Solution: def sortArray(self, nums: List[int]) -> List[int]: def merge_sort(nums): if len(nums) <= 1:
阅读全文
摘要:题目描述: 方法一:第一次提交:python暴力 O(N^2) class Solution: def lastRemaining(self, n: int, m: int) -> int: a = [i for i in range(n)] i = 0 while(len(a) > 1): i =
阅读全文
摘要:题目描述: python 回溯 +kmp next数组 class Solution: def findGoodStrings(self, n: int, s1: str, s2: str, evil: str) -> int: MOD = int(1e9 + 7) m = len(evil) or
阅读全文
摘要:题目描述: python提交: import collections class UndergroundSystem: def __init__(self): self.idloop = collections.defaultdict(list) self.count = collections.d
阅读全文
摘要:题目描述: python提交:O(N^3) class Solution: def numTeams(self, rating: List[int]) -> int: ans = 0 for i in range(len(rating)): for j in range(i,len(rating))
阅读全文
摘要:题目描述: python提交: from typing import List import collections class Solution: def findLucky(self, arr: List[int]) -> int: dic = collections.Counter(arr)
阅读全文
摘要:题目描述: 方法一:O(N) class Solution: def findNumbers(self, nums: List[int]) -> int: ans=0 for num in nums: if len(str(num))%2==0: ans+=1 return ans 方法二:数学 O
阅读全文
浙公网安备 33010602011771号