随笔 - 1133  文章 - 0 评论 - 19 阅读 - 20万
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

03 2020 档案
leetcode201
摘要:1 class Solution: 2 def rangeBitwiseAnd(self, m: int, n: int) -> int: 3 while n > m: 4 n &= (n-1) 5 return n 算法思路:位运算。 “按位与”操作有一个特点,就是 n & (n-1),是将n的最 阅读全文
posted @ 2020-03-31 08:20 Sempron2800+ 阅读(123) 评论(0) 推荐(0) 编辑
leetcode1396
摘要:1 class UndergroundSystem: 2 def __init__(self): 3 self.startStation = collections.defaultdict(lambda: collections.defaultdict(int)) 4 self.endStation 阅读全文
posted @ 2020-03-29 12:44 Sempron2800+ 阅读(211) 评论(0) 推荐(0) 编辑
leetcode1395
摘要:1 class Solution: 2 def __init__(self): 3 #self.l = [] 4 self.count = 0 5 6 def backTrack(self,rating,temp,idx,inc): 7 if inc == 0:#递减 8 if len(temp) 阅读全文
posted @ 2020-03-29 12:38 Sempron2800+ 阅读(188) 评论(0) 推荐(0) 编辑
leetcode1394
摘要:1 class Solution: 2 def findLucky(self, arr: List[int]) -> int: 3 dic = dict() 4 n = len(arr) 5 for i in range(n): 6 if arr[i] not in dic: 7 dic[arr[i 阅读全文
posted @ 2020-03-29 12:37 Sempron2800+ 阅读(179) 评论(0) 推荐(0) 编辑
leetcode1386
摘要:先给出一个TLE的方案,思路很简单: 1 class Solution: 2 def maxNumberOfFamilies(self, n: int, reservedSeats: 'List[List[int]]') -> int: 3 dic_row = dict() 4 for seats 阅读全文
posted @ 2020-03-28 15:39 Sempron2800+ 阅读(195) 评论(0) 推荐(0) 编辑
leetcode1387
摘要:1 class Solution: 2 def getKth(self, lo: int, hi: int, k: int) -> int: 3 memo = dict() 4 memo[1] = 0 5 for i in range(1,hi+1): 6 cur = i 7 count = 0 8 阅读全文
posted @ 2020-03-26 10:54 Sempron2800+ 阅读(189) 评论(0) 推荐(0) 编辑
leetcode1382
摘要:1 class Solution: 2 def __init__(self): 3 self.l = [] 4 5 def inOrder(self,node): 6 if node != None: 7 self.inOrder(node.left) 8 self.l.append(node.va 阅读全文
posted @ 2020-03-26 10:30 Sempron2800+ 阅读(152) 评论(0) 推荐(0) 编辑
leetcode1376
摘要:1 class Solution: 2 def numOfMinutes(self, n: int, headID: int, manager: 'List[int]', informTime: 'List[int]') -> int: 3 graph = collections.defaultdi 阅读全文
posted @ 2020-03-25 08:01 Sempron2800+ 阅读(181) 评论(0) 推荐(0) 编辑
leetcode1391
摘要:1 class Solution: 2 def dfs(self,grid,visited,x,y,m,n): 3 if x < 0 or x >= m or y < 0 or y >= n or visited[x][y] == 1: 4 return False 5 if x == m - 1 阅读全文
posted @ 2020-03-22 12:43 Sempron2800+ 阅读(186) 评论(0) 推荐(0) 编辑
leetcode1390
摘要:1 class Solution: 2 def sumFourDivisors(self, nums: 'List[int]') -> int: 3 result = 0 4 n = len(nums) 5 for i in range(n): 6 s = set() 7 cur = nums[i] 阅读全文
posted @ 2020-03-22 12:38 Sempron2800+ 阅读(167) 评论(0) 推荐(0) 编辑
leetcode1389
摘要:1 class Solution: 2 def createTargetArray(self, nums: List[int], index: List[int]) -> List[int]: 3 n = len(nums) 4 result = [] 5 for i in range(n): 6 阅读全文
posted @ 2020-03-22 12:35 Sempron2800+ 阅读(148) 评论(0) 推荐(0) 编辑
leetcode1385
摘要:1 class Solution: 2 def findTheDistanceValue(self, arr1: List[int], arr2: List[int], d: int) -> int: 3 n1,n2 = len(arr1),len(arr2) 4 result = 0 5 for 阅读全文
posted @ 2020-03-22 12:34 Sempron2800+ 阅读(184) 评论(0) 推荐(0) 编辑
leetcode1379
摘要:1 class Solution: 2 def __init__(self): 3 self.result = TreeNode(-1) 4 5 def preOrder(self,node,target): 6 if node != None: 7 if node.val == target.va 阅读全文
posted @ 2020-03-21 19:23 Sempron2800+ 阅读(163) 评论(0) 推荐(0) 编辑
leetcode1381
摘要:1 class CustomStack: 2 def __init__(self, maxSize: int): 3 self.maxSize = maxSize 4 self.stack = [0] * maxSize 5 self.position = -1 6 7 def push(self, 阅读全文
posted @ 2020-03-21 19:10 Sempron2800+ 阅读(121) 评论(0) 推荐(0) 编辑
leetcode1372
摘要:1 class Solution { 2 int maxpath = 0; 3 HashMap<TreeNode, Integer> map1 = new HashMap<TreeNode, Integer>(); 4 HashMap<TreeNode, Integer> map2 = new Ha 阅读全文
posted @ 2020-03-21 18:03 Sempron2800+ 阅读(158) 评论(0) 推荐(0) 编辑
leetcode1371
摘要:1 class Solution { 2 public int findTheLongestSubstring(String s) { 3 int n = s.length(); 4 Map<Character, Integer> map = new HashMap<>(); 5 map.put(' 阅读全文
posted @ 2020-03-19 09:50 Sempron2800+ 阅读(331) 评论(0) 推荐(0) 编辑
leetcode1380
摘要:1 import sys 2 class Solution: 3 def luckyNumbers (self, matrix: List[List[int]]) -> List[int]: 4 m = len(matrix) 5 n = len(matrix[0]) 6 luckyset = se 阅读全文
posted @ 2020-03-15 12:54 Sempron2800+ 阅读(169) 评论(0) 推荐(0) 编辑
leetcode1375
摘要:1 class Solution: 2 def numTimesAllBlue(self, light: 'List[int]') -> int: 3 right,res = 0,0 4 for i, a in enumerate(light, start=1): 5 right = max(rig 阅读全文
posted @ 2020-03-08 13:10 Sempron2800+ 阅读(143) 评论(0) 推荐(0) 编辑
leetcode1374
摘要:1 class Solution: 2 def generateTheString(self, n: int) -> str: 3 if n == 1: 4 return 'a' 5 elif n == '2': 6 return 'ab' 7 else: 8 if n % 2 == 0: 9 re 阅读全文
posted @ 2020-03-08 13:08 Sempron2800+ 阅读(217) 评论(0) 推荐(0) 编辑
leetcode1370
摘要:1 class Solution: 2 def sortString(self, s: str) -> str: 3 n = len(s) 4 dic = {} 5 for i in range(n): 6 if s[i] not in dic: 7 dic[s[i]] = 1 8 else: 9 阅读全文
posted @ 2020-03-08 03:31 Sempron2800+ 阅读(161) 评论(0) 推荐(0) 编辑
alicode47-超车
摘要:1 package solution47; 2 import java.util.*; 3 class Solution { 4 public int solution(int n, int[] nums1, int[] nums2) { 5 HashMap<Integer, Integer> ma 阅读全文
posted @ 2020-03-07 17:11 Sempron2800+ 阅读(140) 评论(0) 推荐(0) 编辑
alicode46-最大矩形面积
摘要:1 package solution46; 2 import java.util.*; 3 class Solution { 4 public long solution(int n,long[] nums) { 5 long maxNum = 0; 6 long maxSecNum = 0; 7 阅读全文
posted @ 2020-03-07 08:20 Sempron2800+ 阅读(155) 评论(0) 推荐(0) 编辑
alicode45-最活跃的数
摘要:1 package solution45; 2 import java.util.*; 3 class Solution { 4 public int solution(int n, int[] nums) { 5 HashMap<Integer, Integer> map = new HashMa 阅读全文
posted @ 2020-03-07 06:18 Sempron2800+ 阅读(139) 评论(0) 推荐(0) 编辑
alicode44-最大边权和
摘要:1 package solution44; 2 3 import java.util.*; 4 class Solution { 5 public int solution(int n,int[] nums) { 6 Arrays.sort(nums); 7 int maxVal = nums[n- 阅读全文
posted @ 2020-03-07 05:58 Sempron2800+ 阅读(219) 评论(0) 推荐(0) 编辑
alicode43-打怪兽
摘要:1 package solution43; 2 import java.util.*; 3 class Solution { 4 public int solution(int a,int b,int c) { 5 int df1 = Math.abs(a-b); 6 int df2 = Math. 阅读全文
posted @ 2020-03-07 05:46 Sempron2800+ 阅读(129) 评论(0) 推荐(0) 编辑
alicode41-神秘消失
摘要:1 package solution41; 2 import java.util.Stack; 3 class Solution { 4 public int solution(String str) { 5 Stack<Character> S = new Stack<Character>(); 阅读全文
posted @ 2020-03-06 18:19 Sempron2800+ 阅读(143) 评论(0) 推荐(0) 编辑
alicode39-复杂的字符串
摘要:1 package solution39; 2 3 class Solution { 4 public int solution(String s1,String s2) { 5 int n1 = s1.length(); 6 int n2 = s2.length(); 7 int count = 阅读全文
posted @ 2020-03-06 10:20 Sempron2800+ 阅读(162) 评论(0) 推荐(0) 编辑
alicode37-最强的团队
摘要:1 package solution37; 2 3 class Solution { 4 public int solution(int n,int[] a) { 5 int[] preSum = new int[n+1]; 6 for(int i=1;i<=n;i++){ 7 preSum[i] 阅读全文
posted @ 2020-03-06 08:37 Sempron2800+ 阅读(127) 评论(0) 推荐(0) 编辑
alicode35-找出二叉搜索树的第2大的数
摘要:1 package solution35; 2 3 import java.util.LinkedList; 4 5 public class Solution { 6 public LinkedList<Integer> list = new LinkedList<Integer>(); 7 pu 阅读全文
posted @ 2020-03-05 06:03 Sempron2800+ 阅读(246) 评论(0) 推荐(0) 编辑
alicode34-矩阵最小路径和
摘要:1 package solution34; 2 3 class Solution { 4 public int solution(int[][] m) { 5 int row = m.length; 6 int column = m[0].length; 7 int[][] dp = new int 阅读全文
posted @ 2020-03-04 16:25 Sempron2800+ 阅读(203) 评论(0) 推荐(0) 编辑
leetcode1367
摘要:1 class Solution: 2 def __init__(self): 3 self.l = [] 4 5 def preOrder(self,node,temp): 6 if node != None: 7 temp.append(str(node.val)) 8 if node.left 阅读全文
posted @ 2020-03-01 13:59 Sempron2800+ 阅读(204) 评论(0) 推荐(0) 编辑
leetcode1366
摘要:1 class Solution: 2 def rankTeams(self, votes: 'List[str]') -> str: 3 dic = {} 4 n = len(votes) 5 m = len(votes[0]) 6 mat = [[0 for _ in range(26)] fo 阅读全文
posted @ 2020-03-01 13:56 Sempron2800+ 阅读(285) 评论(0) 推荐(0) 编辑
leetcode1365
摘要:1 class Solution: 2 def smallerNumbersThanCurrent(self, nums: List[int]) -> List[int]: 3 sorted_nums = sorted(nums) 4 n = len(nums) 5 index = 0 6 dic 阅读全文
posted @ 2020-03-01 13:54 Sempron2800+ 阅读(175) 评论(0) 推荐(0) 编辑

点击右上角即可分享
微信分享提示