自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(92)
  • 问答 (1)
  • 收藏
  • 关注

原创 leetcode-560 和为K的子数组 Java

https://leetcode-cn.com/problems/subarray-sum-equals-k/solution/he-wei-kde-zi-shu-zu-by-leetcode-solution/方法一:class Solution { public int subarraySum(int[] nums, int k) { int count = 0, pre = 0; HashMap <Integer, Integer> mp =.

2020-05-16 01:15:06 311

原创 leetcode-136 只出现一次的数字 Java

https://leetcode-cn.com/problems/single-number/solution/xue-suan-fa-jie-guo-xiang-dui-yu-guo-cheng-bu-na-y/方法一:哈希表class Solution { public int singleNumber(int[] nums) { Map<Integer, Integer> map = new HashMap<>(); for (I.

2020-05-14 15:58:58 324

原创 leetcode-102 二叉树的层序遍历 Java

https://leetcode-cn.com/problems/binary-tree-level-order-traversal/solution/tao-mo-ban-bfs-he-dfs-du-ke-yi-jie-jue-by-fuxuemin/方法一:DFS/** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * Tree.

2020-05-13 17:24:47 309

原创 leetcode-155 最小栈 Java

https://leetcode-cn.com/problems/min-stack/solution/shi-yong-fu-zhu-zhan-tong-bu-he-bu-tong-bu-python-/方法一:辅助栈和数据栈同步import java.util.Stack;class MinStack { private Stack<Integer> data; private Stack<Integer> helper; /** initial.

2020-05-12 18:04:12 188

原创 leetcode-50 Pow(x, n) Python Java

https://leetcode-cn.com/problems/powx-n/solution/powx-n-by-leetcode-solution/方法一:递归Pythonclass Solution: def myPow(self, x: float, n: int) -> float: def quickMul(N): if N == 0: return 1.0 y = quic.

2020-05-11 16:22:08 157

原创 leetcode-236 二叉树的最近公共祖先 Java

https://leetcode-cn.com/problems/lowest-common-ancestor-of-a-binary-tree/solution/er-cha-shu-de-zui-jin-gong-gong-zu-xian-by-leetc-2/方法一:递归/** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * .

2020-05-10 19:24:23 148

原创 leetcode-572 另一个树的子树

https://leetcode-cn.com/problems/subtree-of-another-tree/solution/xiong-mao-shua-ti-python3-di-gui-pan-duan-liang-ke/# Definition for a binary tree node.# class TreeNode:# def __init__(self, ...

2020-05-07 16:38:43 136

原创 leetcode-983 最低票价 Python

https://leetcode-cn.com/problems/minimum-cost-for-tickets/solution/zui-di-piao-jie-by-leetcode-solution/方法一:class Solution { int[] costs; Integer[] memo; Set<Integer> dayset; ...

2020-05-06 22:50:29 166

原创 leetcode-98 验证二叉搜索树 Java

https://leetcode-cn.com/problems/validate-binary-search-tree/solution/yan-zheng-er-cha-sou-suo-shu-by-leetcode-solution/方法一:中序遍历/** * Definition for a binary tree node. * public class TreeNode {...

2020-05-05 14:07:54 132

原创 leetcode-98 验证二叉搜索树 Python

https://leetcode-cn.com/problems/validate-binary-search-tree/solution/zhong-xu-bian-li-qing-song-na-xia-bi-xu-miao-dong-/方法一:递归# Definition for a binary tree node.# class TreeNode:# def __in...

2020-05-05 13:52:07 169

原创 leetcode-45 跳跃游戏Ⅱ Java

https://leetcode-cn.com/problems/jump-game-ii/solution/tiao-yue-you-xi-ii-by-leetcode-solution/方法一:贪心class Solution { public int jump(int[] nums) { int position = nums.length - 1; ...

2020-05-04 15:30:19 161

原创 leetcode-53 最大子序和 Java

https://leetcode-cn.com/problems/maximum-subarray/solution/bao-li-qiu-jie-by-pandawakaka/方法一:贪心class Solution { public int maxSubArray(int[] nums) { int cur = 0; int res = nums...

2020-05-03 14:25:41 146

原创 leetcode-3 滑动窗口 Python

方法一:class Solution: def lengthOfLongestSubstring(self, s: str) -> int: occ = set() n = len(s) rk, ans = -1, 0 for i in range(n): if i != 0: ...

2020-05-02 13:20:24 284

原创 leetcode-21合并两个有序链表

https://leetcode-cn.com/problems/merge-two-sorted-lists/solution/he-bing-liang-ge-you-xu-lian-biao-by-leetcode-solu/方法一:迭代# Definition for singly-linked list.# class ListNode:# def __init__(...

2020-05-01 12:25:51 145

原创 leetcode-202 快乐数 Python

https://leetcode-cn.com/problems/happy-number/solution/kuai-le-shu-by-leetcode-solution/方法一:集合class Solution: def isHappy(self, n: int) -> bool: if n < 0: return Fals...

2020-04-30 20:02:07 237

原创 leetcode-1095 山脉数组中查找目标值 Python

方法一:二分查找https://leetcode-cn.com/problems/find-in-mountain-array/solution/shan-mai-shu-zu-zhong-cha-zhao-mu-biao-zhi-by-leet/# """# This is MountainArray's API interface.# You should not implemen...

2020-04-29 15:19:40 156

原创 leetcode-面55-Ⅰ 数组中数字出现的次数

方法一:字典https://leetcode-cn.com/problems/shu-zu-zhong-shu-zi-chu-xian-de-ci-shu-lcof/solution/python3-zi-dian-qiao-jie-by-mu-ren-6/class Solution: def singleNumbers(self, nums: List[int]) -> ...

2020-04-28 16:30:09 118

原创 leetcode-23 合并K个排序链表 Python

https://leetcode-cn.com/problems/merge-k-sorted-lists/solution/xiong-mao-shua-ti-python3-3chong-jie-fa-bao-li-you/方法一:暴力法# Definition for singly-linked list.# class ListNode:# def __init__(s...

2020-04-26 19:02:58 120

原创 leetcode-46 全排列 Python

方法一:class Solution: def permute(self, nums: List[int]) -> List[List[int]]: return list(itertools.permutations(nums))方法二:class Solution: def permute(self, nums: List[int]) ->...

2020-04-25 19:53:08 128

原创 Error: 错误: 编码 GBK 的不可映射字符 (0x93)

解决方法:编译时加上 -encoding utf-8例如:javac -encoding utf-8 NBody.java

2020-04-25 14:09:57 944

原创 Error: *.java使用或覆盖了已过时的 API。

解决方法:编译加上-Xlint:deprecation例如javac -Xlint:deprecation NBody.java

2020-04-25 14:09:06 3993 2

原创 leetcode-面51 数组中的逆序对 Python

https://leetcode-cn.com/problems/shu-zu-zhong-de-ni-xu-dui-lcof/solution/shu-zu-zhong-de-ni-xu-dui-by-leetcode-solution/方法一:归并排序class Solution: def mergeSort(self, nums, tmp, l, r): if...

2020-04-24 13:40:59 152

原创 leetcode-面08.11 硬币 Python

https://leetcode-cn.com/problems/coin-lcci/solution/ying-bi-by-leetcode-solution/方法一:动态规划class Solution: def waysToChange(self, n: int) -> int: mod = 10**9 + 7 coins = [25, ...

2020-04-23 19:07:47 135

原创 leetcode-199 二叉树的右视图 Python

方法一:DFS# Definition for a binary tree node.# class TreeNode:# def __init__(self, x):# self.val = x# self.left = None# self.right = Noneclass Solution: def right...

2020-04-22 17:31:06 173

原创 leetcode-1248 统计[优美子数组] Python

方法一:class Solution: def numberOfSubarrays(self, nums: List[int], k: int) -> int: res, cnt, idx = 0, 0, [-1] for i, num in enumerate(nums): cnt += num % 2 ...

2020-04-21 11:35:14 128

原创 报错Unmet dependencies. Try 'apt --fix-broken install' with no packages (or specify a solution).解决方法

在Ubuntu中用apt-get安装软件,系统报出Unmet dependencies错误。Unmet dependencies. Try ‘apt --fix-broken install’ with no packages (or specify a solution)Unmet dependencies. Try 'apt --fix-broken install' with no pa...

2020-04-20 17:59:24 16961 7

原创 leetcode-200 岛屿数量 Python

方法一:DFSclass Solution: def dfs(self, grid, r, c): grid[r][c] = 0 nr, nc = len(grid), len(grid[0]) for x, y in [(r-1, c), (r+1, c), (r, c-1), (r, c+1)]: if 0 &l...

2020-04-20 11:40:07 187

原创 leetcode-56 合并区间 Python

参考地址class Solution: def merge(self, intervals: List[List[int]]) -> List[List[int]]: if len(intervals) == 0: return [] res = [] intervals.sort(key=lambda x:x...

2020-04-16 13:56:47 147

原创 leetcode-542 01矩阵 Python

class Solution: def updateMatrix(self, matrix: List[List[int]]) -> List[List[int]]: res = [[None for _ in range(len(matrix[0]))] for _ in range(len(matrix))] # 设定结果集 q = collec...

2020-04-15 02:18:38 238

原创 leetcode-887 鸡蛋掉落 Python

方法一:class Solution: def superEggDrop(self, K: int, N: int) -> int: dp = [[0 for _ in range(N+1)] for _ in range(K+1)] for m in range(1,N+1): dp[0][m] = 0 #无鸡蛋 ...

2020-04-11 16:08:47 175

原创 leetcode-151 翻转字符串里的单词 Python

方法一:class Solution: def reverseWords(self, s: str) -> str: a = s.split() ans = "" for i in range(len(a)-1,-1,-1): ans += a[i] ans += " " ...

2020-04-10 18:14:23 133

原创 leetcode-22 括号生成 Python

方法一:暴力法class Solution: def generateParenthesis(self, n: int) -> List[str]: def generate(A): if len(A) == 2*n: if valid(A): ans.append(""...

2020-04-09 23:44:43 146

原创 UCB CS 61B -GIT 基础

UCB git 使用教程:git init: Creates a box in which to permanently store panoramic pictures.git add: Takes a temporary photo of one thing that can be assembled into a panoramic photo later.git commit: As...

2020-04-09 01:49:29 310

原创 Git Bash修改默认打开之后的路径

Git Bash打开之后的默认路径是“/c/Users/Administrator”,为了方便使用自己创建的repository,我们将其设置进行修改。第一步:右键git bash属性首先将“目标”后面的“–cd-to-home”删除,这条命令在快捷方式打开的时候切换到“/c/Users/Administrator”路径。第二步:添加所需路径将起始位置修改为自己想要的路径即可,这里我改成...

2020-04-09 00:47:59 501

原创 leetcode-面13 机器人的运动范围 Python

方法1:深度优先遍历DFSclass Solution: def movingCount(self, m: int, n: int, k: int) -> int: def dfs(i, j, si, sj): if i >= m or j >= n or k < si + sj or (i,j) in visited: r...

2020-04-08 23:36:16 138

原创 leetcode-72 编辑距离 Python

class Solution: def minDistance(self, word1: str, word2: str) -> int: m = len(word1) n = len(word2) dp = [[0 for _ in range(n + 1)] for _ in range(m + 1)] for i ...

2020-04-07 00:23:54 126

原创 leetcode-460 LFU缓存 Python

方法一:class LFUCache: def __init__(self, capacity: int): self.c, self.__count = capacity, 0 self.keys = {} # {key:int, value = [value, fre, time]} def get(self, key: int) -&gt...

2020-04-06 00:33:16 215

原创 leetcode-42 接雨水 Python

方法一:暴力(超时)class Solution: def trap(self, height: List[int]) -> int: ans = 0 size = len(height) for i in range(size): max_left = 0 max_right = 0...

2020-04-04 16:46:42 303

原创 leetcode-8 字符串转换整数(atoi) Python

方法一:class Solution: def myAtoi(self, str: str) -> int: INT_MAX = 2**31 - 1 INT_MIN = -2**31 if not str: return 0 str = str.strip() size = le...

2020-04-03 23:53:52 173

原创 leetcode-1111 有效括号的嵌套深度 Python

方法一:class Solution: def maxDepthAfterSplit(self, seq: str) -> List[int]: ans = [] a = b = 0 #深度 for s in seq: if s == '(': if a <= b: ...

2020-04-01 23:28:53 169

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除