随笔分类 - leetcode
摘要:题目描述: 方法一:动态规划 O(N) class Solution: def translateNum(self, num: int) -> int: str_num = str(num) n = len(str_num) dp = [1 for _ in range(n + 1)] for i
阅读全文
摘要:题目描述: 方法:前缀和+状态压缩 O(N) class Solution: def findTheLongestSubstring(self, s: str) -> int: bit_mask = eval('0b00000') state_first_idx = {eval('0b00000')
阅读全文
摘要:方法:自定义排序:O(logn) class Solution { public String minNumber(int[] nums) { String[] strs = new String[nums.length]; for(int i = 0; i < nums.length; i++)
阅读全文
摘要:提交:O(N) O(1) class Solution: def validPalindrome(self, s: str) -> bool: def helper(s): if s == s[::-1]: return True return False l,r = 0,len(s) - 1 wh
阅读全文
摘要:方法一: 来自讨论区 https://leetcode-cn.com/circle/discuss/Z2oiVE/ class Solution: def numPoints(self, p: List[List[int]], r: int) -> int: eps = 1e-8 def dist(
阅读全文
摘要:题目描述: 提交: class Solution: def peopleIndexes(self, f: List[List[str]]) -> List[int]: res = [] dic = collections.defaultdict(list) for i in range(len(f)
阅读全文
摘要:题目描述: 提交: class Solution: def arrangeWords(self, text: str) -> str: text = text.lower().split(" ") text.sort(key = lambda x:len(x)) text[0] = text[0][
阅读全文
摘要:提交: class Solution: def busyStudent(self, startTime: List[int], endTime: List[int], queryTime: int) -> int: count = 0 for i in range(len(startTime)):
阅读全文
摘要:题目描述: 方法一:找规律 class Solution { public int findNthDigit(int n) { int digit = 1; long start = 1; long count = 9; while(n > count){ n -= count; digit +=
阅读全文
摘要:题目描述: 提交:背包问题 class Solution: def largestNumber(self, cost, target: int) -> str: dp = [[0 for _ in range(target + 1)] for _ in range(10)] def tmax(a,b
阅读全文
摘要:题目描述: 提交: class Solution: def goodNodes(self, root: TreeNode) -> int: def helper(m,node): r,left,right = 0,0,0 if node.val >= m: r = 1 if node.left: l
阅读全文
摘要:题目描述: 提交: class Solution: def simplifiedFractions(self, n: int) -> List[str]: def gcd(a, b): if b > a: return gcd(b, a) if a % b == 0: return b return
阅读全文
摘要:题目描述: 方法一:栈 class Solution { public ListNode reverseKGroup(ListNode head, int k) { Deque<ListNode> stack = new ArrayDeque<>(); ListNode dummy = new Li
阅读全文
摘要:方法:前缀和 + 哈希表 O(N) class Solution { public int subarraySum(int[] nums, int k) { int count = 0,pre = 0; HashMap <Integer,Integer> mp = new HashMap<> ();
阅读全文
摘要:题目描述: 方法: class Solution { public int countDigitOne(int n) { int digit = 1,res = 0; int high = n / 10,cur = n % 10,low = 0; while(high != 0 || cur !=
阅读全文
摘要:题目描述: 方法一:快排 O(N) java class Solution { public int[] getLeastNumbers(int[] arr, int k) { if(k == 0|| arr.length == 0){ return new int[0]; } return qui
阅读全文
摘要:题目描述: 提交:O(N) class Solution: def buildArray(self, target: List[int], n: int) -> List[str]: res = [] a = "Push" b = "Pop" index = 1 for i in target: w
阅读全文
摘要:题目描述: 提交:O(N3) class Solution: def countTriplets(self, arr: List[int]) -> int: # count = 0 # for i in range(len(arr)): # for j in range(i+1,len(arr)):
阅读全文
摘要:题目描述: 解:动态规划 参考自: 作者:coldme-2链接:https://leetcode-cn.com/problems/number-of-ways-of-cutting-a-pizza/solution/dong-tai-gui-hua-by-coldme-2-2/来源:力扣(LeetC
阅读全文
摘要:题目描述: 方法一:dfs 从父节点到子节点 class Solution: def minTime(self, n: int, edges: List[List[int]], hasApple: List[bool]) -> int: maps = collections.defaultdict(
阅读全文
浙公网安备 33010602011771号