自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(30)
  • 收藏
  • 关注

原创 LeetCode每日随机2021/3/31

题思一个一个试过去呗。代码class Solution { public String findLongestWord(String s, List<String> dictionary) { int max = -1; String result = ""; for (String temp : dictionary) { if (temp.length() >= max && temp.length() <= s.length(

2021-03-31 22:47:13 89

原创 Leetcode每日随机2021/3/29

题思O(n)想不出来,看题解的;dp还是不熟练。代码public int maxSubArray(int[] nums) { int[] dp = new int[nums.length]; dp[0] = nums[0]; int max = dp[0]; for (int i = 1; i < dp.length; i++) { dp[i] = Math.max(dp[i - 1] + nums[i], nums[i]); max = dp[i] >

2021-03-29 14:30:16 73

原创 Leetcode每日随机2021/3/28

题思前天事情太多,昨天休息了一天。今天继续。这题难度不大,有点dp的味道。我这次写的代码可以说是完美的,时间复杂度O(n),空间复杂度O(1),跑出来的成绩也很好看。主要思路就是用一个数组记录当前状态下,以各个字母结尾的单词的数量,我们不用知道每个单词是什么。那么在下一轮中,以i结尾的数量就是以a和e结尾的数量的和,依次类推。以a结尾的数量永远是1。我看了一下那些题解,写的真烂,跟我的差远了,我要去教育一下他们了。代码class Solution { public int co

2021-03-28 15:13:09 138

原创 Leetcode每日随机2021/3/25

题思憨憨题代码class Solution { public int[] twoSum(int[] numbers, int target) { Map<Integer, Integer> map = new HashMap<Integer, Integer>(); for (int i = 0; i < numbers.length; i++) { if (map.containsKey(target - numbers[i])) {

2021-03-25 15:56:36 105

原创 Leetcode每日随机2021/3/24

题思找到买点和卖点即可。什么时候买?第二天会涨;什么时候卖?第二天会跌;代码class Solution { public int maxProfit(int[] prices) { int profit = 0, buyday = findBuyDay(0, prices); if (buyday < 0) { return 0; } while (true) { for (int i = buyday + 1; i < prices.len

2021-03-24 14:24:35 117

原创 Leetcode每日随机2021/3/23

题思感觉可以做,但是没时间多想了。第一个题解用栈解得很漂亮。有时候删a,有时候删b,无非就是那个短删哪个。代码class Solution { public int minimumDeletions(String s) { int count = 0; Stack<Character> stack = new Stack<Character>(); for (int i = 0; i < s.length(); i++) { if (s.

2021-03-23 11:23:05 81

原创 Leetcode每日随机2021/3/22

题思很难见到这么脑瘫的题了。代码class Solution { public double average(int[] salary) { int min = Integer.MAX_VALUE, max = Integer.MIN_VALUE, sum = 0; for (int i : salary) { min = i < min ? i : min; max = i > max ? i : max; sum += i; } retur

2021-03-22 11:10:02 91

原创 Leetcode每日随机2021/3/21

题思还是看了题解里的一些思路才写出来的,虽然没做出来,但是这题还是比较有意思的。升序这个就是唬人的,升序一个等于没动,升序两个等于交换,升序两个以上都可以用升序两个完成。对于t中的每一个字符,只要保证其在s中的位置之后的每一个字符都是小于它的即可。因此一开始写了一版就是遍历t中的每一个字符,然后从后往前找到其在s中的位置,然后判断是否满足上述条件。超时……然后优化了一下,上一版其实是一个三重循环,复杂度到n^3了。遍历s和判断其是否满足条件其实可以一起做,这样就变成了一个二重循环。超时…

2021-03-21 14:43:12 161

原创 Leetcode每日随机2021/3/20

题思做不来啊,答案也看不懂。代码class Solution { Map<String, Integer> memo; int x; public int leastOpsExpressTarget(int x, int target) { memo = new HashMap(); this.x = x; return dp(0, target) - 1; } public int dp(int i, int target) { String c

2021-03-20 15:51:19 124

原创 Leetcode每日随机2021/3/19

题思一些细节考虑清楚就行了。代码class Solution { public String reverseStr(String s, int k) { char[] arr = s.toCharArray(); // 处理所有完整的2k区域 for (int i = 0; i < arr.length - arr.length % (2 * k); i += 2 * k) { for (int j = i; j < i + k / 2; j++) {

2021-03-19 19:35:32 102

原创 Leetcode每日随机2021/3/18

题思又碰到了这种一看就做不出来的题。感谢这位老哥的题解,这写的不比官方题解清楚多了?回溯,学到了。代码class Solution { public List<Integer> splitIntoFibonacci(String s) { List<Integer> res = new ArrayList<Integer>(); backtrack(s, res, 0); return res; } private boolean

2021-03-18 11:26:09 76

原创 Leetcode每日随机2021/3/17

题思给定一个开头,判断下这个开头重复了几次即可,若>=k次则成功。若小于k次则换到下一个开头。代码class Solution { public boolean containsPattern(int[] arr, int m, int k) { if (arr.length < m * k) { return false; } if (k == 1) { return true; } for (int i = 0; i + m * k &l

2021-03-17 12:39:16 73

原创 Leetcode每日随机2021/3/16

题思先用dp预处理一下数组,找到每个黑点的右边有多少黑点,下方有多少黑点。然后循环遍历每一个黑点,边长取右侧黑点和下侧黑点的较小值,注意这里还要用循环,因为比如边长5不满足,但是4可能就满足了,只要大于当前已知的最大size即可。代码class Solution { public int[] findSquare(int[][] matrix) { int[] res = { 0, 0, 0 }; int[][] dpRow = new int[matrix.length][mat

2021-03-16 11:39:57 124

原创 Leetcode每日随机2021/3/15

题思没什么好说的代码class Solution { public boolean isSubsequence(String s, String t) { int i = 0, j = 0; while (i < s.length() && j < t.length()) { if (s.charAt(i) == t.charAt(j)) { i++; } j++; } if (i == s.length()) {

2021-03-15 10:44:04 122

原创 leetcode每日做题2021/3/14

题思做不来啊。代码是这位老哥的题解代码class Solution { public String largestNumber(int[] cost, int target) { int[] dp = new int[target + 1]; Arrays.fill(dp, Integer.MIN_VALUE); dp[0] = 0; for (int i = 1; i <= target; i ++) {

2021-03-14 18:00:39 81

原创 Leetcode每日随机2021/3/13

题思看了下题目,我一行代码没写就知道我做不出来。我知道肯定是贪心来做,最大高度差用梯子,最小的高度差用砖头。答案是用优先队列,Java中的PriorityQueue,我之前还真没用过这个,这次也是学到了。感谢这位老哥的题解思路是这样的,每次能用梯子就用梯子,而且把高度差存到优先队列里。梯子用完了怎么办?弹出队列里的一个高度差,因为是优先队列,弹出的一定是高度最小的一个,把这个改成用砖头,这样等于又多出了一个梯子。最后梯子也没了,砖头也不够了,那这个高度就跨不过去了。代码class S

2021-03-13 17:21:57 74

原创 SpringData简单梳理

SpringData简单梳理文章目录SpringData简单梳理引Jpa依赖配置实体类Dao测试案例Redis依赖配置实体类测试案例ElasticSearch依赖配置实体类Dao测试案例MongoDB依赖配置实体类Dao测试案例作者:李晶晶;日期;2021年3月12日;引其实好几天之前这几个demo就写好了,但一直没时间写篇文档来总结一下,事情有点多,人也有点累。SpringData是一个持久层的通用解决方案,目的是统一不同持久层的操作api。原来比如MySql,redis他们需要提供一套

2021-03-12 14:29:59 117

原创 Leetcode每日随机2021/3/12

题思就直接在外接正方形生成一个坐标判断一下在不在圆内就行了。这题难度配不上中等。代码class Solution { double radius; double x_center; double y_center; Random r = new Random(); public Solution(double radius, double x_center, double y_center) { this.radius = radius; this.x_

2021-03-12 11:16:15 93

原创 Leetcode每日随机2021/3/11

题思没做出来,参考LeetCode每日一题:第N个数字(No.400)。状态不行,太累了,头昏昏的。就这样吧代码class Solution { public int findNthDigit(int n) { int digit = 1, numCount = 9; while (n > numCount) { n -= numCount; digit++; numCount = (int) (9 * Math.pow(10, digit - 1) *

2021-03-11 15:09:29 97

原创 Leetcode每日随机2021/3/10

题思就是定义一个排序规则而已。代码class Solution { public String minNumber(int[] nums) { Integer[] arr = Arrays.stream(nums).boxed().toArray(Integer[]::new); Arrays.sort(arr, (a, b) -> compare(a, b)); StringBuilder sb = new StringBuilder(); Arrays.strea

2021-03-10 13:05:57 96

原创 Leetcode每日随机2021/3/9

题思一开始按规则变化行列索引,结果超时。看了下超时的例子,发现就是只有一列,所以超时的原因就是有太多的的nums[row][col]不存在了,多判断了很多时间。所以就只能先把数据取出来排个序(按行列和以及行号排序),再把值那一列取出来即可。代码class Solution { public int[] findDiagonalOrder(List<List<Integer>> nums) { List<int[]> result =

2021-03-09 14:13:30 99

原创 KMP算法详解

KMP算法详解文章目录KMP算法详解介绍问题引入暴力解法next数组的介绍KMP算法流程过程代码如何求next数组作者:木子六日;日期:2021年3月8日;介绍问题引入假设有一个字符串a和字符串b;若b是a子串,返回b在a中的位置,如a="xxyyzz",b="zz",则返回4;若b不是a的子串,则返回-1;暴力解法暴力显然是可以做的,我们判断a每一个位置作为开头能否匹配出b即可,时间复杂度就是a.length*b.length;KMP算法其实也是这个思路,只不过回退的策略发生改变

2021-03-08 15:29:13 153

原创 Leetcode每日随机2021/3/8

题思暴力可过代码class Solution { public int numMatchingSubseq(String s, String[] words) { int count = 0; for (String w : words) { if (isSubSeq(s, w)) { count++; } } return count; } private boolean isSubSeq(String s, String word) { i

2021-03-08 11:18:40 100

原创 Leetcode每日随机2021/3/7

题思。。。。。。代码class Solution { public int minArray(int[] numbers) { if (numbers.length < 2 || numbers[0] < numbers[numbers.length - 1]) { return numbers[0]; } for (int i = 1; i < numbers.length; i++) { if (numbers[i] < nu

2021-03-07 21:47:05 129

原创 Leetcode每日随机2021/3/6

题思记得小学就有这个问题。最后剩两个瓶怎么办?按这题的做法是换不了了。但那时候老师说可以先向店家借一瓶酒,喝了之后剩三个空瓶再去换一瓶还给店家,哈哈。这个说法给我留下了很深的印象,以至于到现在还记得,没想到能在力扣上看到这个问题。代码class Solution { public int numWaterBottles(int numBottles, int numExchange) { int count = numBottles, exchange = 0; while

2021-03-06 22:05:48 126

原创 Leetcode每日随机2021/3/5

题思一看就是BFS的题。但是地图太大了,纯bfs的话会超时。题目中正好给了blocked的大小限制,我们就让遍历足够多的节点后停下来就行了。我也比较快的想到这点了,但是这题还是把我恶心到了。恶心的地方就是我用红框框出的部分,去你码的,骗人!害老子找了那么久问题,cnm!以后用例能不能认真写一下啊leetcode。代码class Solution { private int max = (int) Math.pow(10, 6); private int maxArea =

2021-03-05 22:46:10 78

原创 Leetcode每日随机2021/3/4

题思也没什么好说,就遍历一下所有可能性。代码class Solution { public int numSubarrayBoundedMax(int[] A, int L, int R) { int num = 0; for (int i = 0; i < A.length; i++) { int max = A[i]; if (max > R) { continue; } for (int j = i; j < A.length

2021-03-04 11:24:39 147 1

原创 Leetcode每日随机2021/3/3

题思怎么说呢,真的看不懂题目的难度设置,这就是一个简单题。没什么好说的,找数组中位数。代码class Solution { public int minMoves2(int[] nums) { Arrays.sort(nums); int mid = nums[nums.length/2]; int move = 0; for (int i : nums) { move += Math.abs(i-mid); } return move; }}..

2021-03-03 12:06:55 93

原创 Leetcode每日随机2021/3/2

题思此题超出能力范围,不是我能做出来的。官方题解很妙。翻译一下题目的意思:找出一个最短字符串,使得这个字符串包含了[0,1,……k-1]的长度为n所有排列。对于每一种排列,题解中使用前n-1个字符作为节点,每个节点有k条边,这样,由于入度等于出度,到最后就必然只剩下初始节点未被访问。因此此图必有欧拉回路。题解中使用Hierholzer算法找出欧拉回路,具体做法就是深搜,若提前回到原点,则换一个点再来(代码中使用深搜中循环遍历[0……k-1]的方式解决)。以下代码为官方题解。代码clas

2021-03-02 14:12:04 110

原创 Leetcode每日随机2021/3/1

题思这题可以加入脑瘫题行列。代码class Solution { public String[] uncommonFromSentences(String A, String B) { Map<String, Integer> aCount = new HashMap<String, Integer>(); Map<String, Integer> bCount = new HashMap<String, Integer>();

2021-03-01 11:14:34 65

空空如也

空空如也

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

TA关注的人

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