自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

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

原创 力扣教我学置换环算法

置换环

2022-11-14 16:30:05 918 1

转载 力扣教我学线段树

线段树

2022-10-07 08:29:47 226

原创 leetcode417

题目考查逆向思维,水可以向低处流,但是遍历需要重复遍历各个节点,换个角度,水可以向高处流,可以采用DFS或者BFS一次遍历即可暴力水往低处流(剪枝优化才能AC) class Solution { static int[][] dirs = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}}; int[][] heights; int m, n; boolean[][] pacific; boolean[]

2022-04-28 09:56:25 193

原创 leetcode33

题目这道题主要就是需要观察规律,旋转数组一定存在左边是升序或者右边是升序的情况,根据该情况进行分类讨论即可第一步就是区分那一边的数组是升序还是无序class Solution { public int search(int[] nums, int target) { int left = 0; int right = nums.length - 1; while (left <= right) {

2022-04-27 14:34:11 121

原创 leetcode883

题目数组在遍历的时候,grid[i][j]为横坐标,grid[j][i]就是纵坐标class Solution { public int projectionArea(int[][] grid) { int n = grid.length; int xyArea = 0, yzArea = 0, zxArea = 0; for (int i = 0; i < n; i++) { int yzHeight = 0, zx

2022-04-26 22:04:35 115

原创 leetcode103

题目public class TreeNode { int val; TreeNode left; TreeNode right; TreeNode() { } TreeNode(int val) { this.val = val; } TreeNode(int val, TreeNode left, TreeNode right) {

2022-04-26 20:48:36 66

原创 leetcode398

考查数学概率题目方法一:class Solution { private Map<Integer, List<Integer>> records = new HashMap<>(); private Random random; public Solution(int[] nums) { for (int i = 0; i < nums.length; i++) {

2022-04-25 16:49:51 63

原创 leetcode207

拓扑排序在图论中,拓扑排序(Topological Sorting)是一个有向无环图(DAG, Directed Acyclic Graph)的所有顶点的线性序列。且该序列必须满足下面两个条件:每个顶点出现且只出现一次。若存在一条从顶点 A 到顶点 B 的路径,那么在序列中顶点 A 出现在顶点 B 的前面。有向无环图(DAG)才有拓扑排序,非DAG图没有拓扑排序从 DAG 图中选择一个 没有前驱(即入度为0)的顶点并输出。从图中删除该顶点和所有以它为起点的有向边。重复 1 和 2 直到当前

2022-04-25 16:17:29 166

原创 leetcode868

题目考查二进制&运算,因为&运算,能够从最低位判断该位等于1还是0public int binaryGap(int n) { int ans = 0; String str = toBinary(n); int left = -1; int index = 0; while (index < str.length()) { if (str.charAt(index) == '1'

2022-04-24 17:45:56 373

原创 leetcode868

题目考查二进制&运算,因为&运算,能够从最低位判断该位等于1还是0public int binaryGap(int n) { int ans = 0; String str = toBinary(n); int left = -1; int index = 0; while (index < str.length()) { if (str.charAt(index) == '1'

2022-04-24 11:18:45 205

原创 leetcode396

题目暴力Time Out//两次遍历会Time Out public static int maxRotateFunction(int[] nums) { //模拟循环链表 int length = nums.length; int max = Integer.MIN_VALUE; for (int i = length; i > 0; i--) { int index = i;

2022-04-22 22:41:48 268

原创 leetcode450

题目我的思路public TreeNode deleteNode(TreeNode root, int key) { if (root == null) { return null; } //创建一个临时节点,表示root的父节点,相当于preRoot值是Integer.MAX_VALUE // 目的是因为如果root节点是被删除节点,preRoot可以少很多判断。

2022-04-22 18:48:26 258

原创 leetcode824

题目public String toGoatLatin(String sentence) { Set<Character> chars = new HashSet<Character>() {{ add('a'); add('e'); add('i'); add('o'); add('u'); add('A');

2022-04-21 11:45:17 57

原创 leetcode124

题目考查递归我的思路第一次20分钟做出一道困难题。。private int max = Integer.MIN_VALUE; public int maxPathSum(TreeNode root) { if (root == null) { return 0; } dfs(root); return max; } public int dfs(TreeNode root) {

2022-04-21 11:22:24 80

原创 leetcode236

codeTop题目二叉树后序遍历public TreeNode lowestCommonAncestor(TreeNode root, TreeNode p, TreeNode q) { if (root == null || root.val == p.val || root.val == q.val) { return root; } TreeNode left = lowestCommonAncestor(root.left

2022-04-20 18:27:25 376

原创 leetcode388

codeTop题目考查如何保存上一次的结果方法一:递归,方法二:数组,或者栈//我刚开始的思想是直接对其进行'\t'分割,递归之后对于'\t\t'分割, // 但是发现,第一次递归对于'\t'分割,已经不能行的通了。 //既然递归行不通,可以借助栈,采取手动解析的方式。 //如何判断下一个节点是栈顶元素的下一个目录节点?采用深度来判断。每个'\t'代表一个深度。 //其实这道题就是考查,如何记录已经遍历过的节点,方法一:递归,方法二:数组,或者栈 public

2022-04-20 18:23:26 899

原创 leetcode821

题目链接我的思路//将s中==c的记录下来到数组arr中,然后遍历s,对于arr进行二分查找,找到第一个小于该下标的位置, public int[] shortestToChar(String s, char c) { int length = s.length(); int[] ans = new int[length]; List<Integer> res = new ArrayList<>(); for

2022-04-20 09:29:50 204

原创 leetcode206反转链表

codeTop题目链接//方法一: public ListNode reverseList(ListNode head) { ListNode pre = null; while (head != null) { ListNode nex = head.next; head.next = pre; pre = head; head = nex; }

2022-04-20 09:27:31 336

原创 leetcode215数组中的第K个最大元素

codeTop 微软刷题题目链接这道题考查最基本的排序功能,看能不能写出来快速排序private final Random random = new Random(); public int findKthLargest(int[] nums, int k) { return randomPartition(nums, 0, nums.length - 1, nums.length - k); } //平均情况下快速排序的时间复杂度是Θ(𝑛\lgn),最坏

2022-04-19 14:18:50 74

原创 leetcode396

从今天开始,每天至少一道题题目链接leetcode386标准的递归回溯public List<Integer> lexicalOrder(int n) { List<Integer> ans = new ArrayList<>(); for (int i = 1; i < 10; i++) { dfs(ans, String.valueOf(i), n); } retur

2022-04-18 21:38:35 200

原创 Redis下载与安装及RDB使用

redis下载redis官网找到下载项,下载stable版本redis安装新建文件夹:Documents/software/redis/mv redis-6.2.6.tar.gz到该文件夹tar -zxvf redis-6.2.6.tar.gzcd redis-6.2.6/src/ 进入src目录sudo makesudo make testsudo make PREFIX=../ install,在src同级目录下install运行redis所需要的文件cd ../bin 进入bi

2022-04-13 15:22:18 1033

原创 leetcode375

leetcode375public class findRadius475 { /** * 刚开始的想法是要遍历每个加热器,所以思路就是错的,我们的肯本目标是让房子有暖气,所以应该遍历房子 * @param houses * @param heaters * @return */ public int findRadius(int[] houses, int[] heaters) { Arrays.sort(heaters)

2021-12-20 19:04:25 88

原创 leetcode630

题目链接leetcode630public class scheduleCourse630 { /** * 贪心,有限选择课程结束时间早的,考虑 [[5,5],[4,6],[2,6]],如果执行先学习[5,5],发现后面的都不能学习,但是发现5 > 2,那么可以将5抛出,替换为2,是为了缩小时间差 * @param courses * @return */ public int scheduleCourse(int[][] courses)

2021-12-14 18:30:37 193

原创 leetcode807

题目链接leetcode807class Solution { public int maxIncreaseKeepingSkyline(int[][] grid) { int ans = 0; int n = grid.length; int[] west = new int[n]; int[] north = new int[n]; for (int i = 0; i < n; i++) {

2021-12-13 18:41:46 159

原创 leetocde709

题目链接leetocde709public class toLowerCase709 { public String toLowerCase(String s) { StringBuilder sb = new StringBuilder(); for (int i = 0; i < s.length(); i++) { char c = s.charAt(i); if(c >= 65 &&

2021-12-12 12:35:13 3737

原创 leetcode911

题目链接leetcode911class TopVotedCandidate { private int[] persons; private int[] times; private int length; int[] dp; int[] count; public TopVotedCandidate(int[] persons, int[] times) { this.persons = persons; this.

2021-12-11 20:48:15 165

原创 leetcode748

题目链接leetcode748int[] thymeleaf = new int[26]; public String shortestCompletingWord(String licensePlate, String[] words) { String ans = ""; int minlength = 16; licensePlate = licensePlate.toLowerCase(); for (int i = 0;

2021-12-10 14:25:22 178

原创 关于产品的一些思考

产品,明确产品需求,我设计这个产品是干什么用的面向陌生人?-> 客户细分每个产品都有自己的理念 -> 价值主张点赞太多会变得廉价,所以微信朋友圈点赞放到第二层,那为什么短视频点赞放到第一层短视频是面向陌生人短视频短,在于浏览量,在于用户在线时长沉浸式体验,不自觉的就点赞了刷短视频的人都懒,放第二层,我懒,我为什么要点短视频所带来的广告收益:沉浸式,好的视频有购买的欲望微信没有已读未读为了推卸责任普通的发个消息 -> 有时看不见,影响紧急事情电话-> 所

2021-10-19 16:31:42 74

原创 力扣教我学前缀树

Trie,又称前缀树或字典树,是一棵有根树,其每个节点包含以下字段:指向子节点的指针数组 children。对于本题而言,数组长度为 26,即小写英文字母的数量。此时 children[0] 对应小写字母 a,children[1] 对应小写字母 b,…,children[25] 对应小写字母 z。布尔字段 isEnd,表示该节点是否为字符串的结尾。插入字符串我们从字典树的根开始,插入字符串。对于当前字符对应的子节点,有两种情况:子节点存在。沿着指针移动到子节点,继续处理下一个字符。子节点不存在

2021-10-19 11:26:39 58

原创 leetcode230. 二叉搜索树中第K小的元素

题目描述给定一个二叉搜索树的根节点 root ,和一个整数 k ,请你设计一个算法查找其中第 k 个最小元素(从 1 开始计数)。输入:root = [3,1,4,null,2], k = 1输出:1递归 private int count = 0; private int ans = -1; public void dfs(TreeNode root, int k) { if (root == null || ans == -1) return;

2021-10-18 11:49:39 64

原创 leetcode 剑指offer 069

题目描述符合下列属性的数组 arr 称为 山峰数组(山脉数组) :arr.length >= 3存在 i(0 < i < arr.length - 1)使得:arr[0] < arr[1] < ... arr[i-1] < arr[i]arr[i] > arr[i+1] > ... > arr[arr.length - 1]给定由整数组成的山峰数组 arr ,返回任何满足 arr[0] < arr[1] < ... arr[i -

2021-10-14 11:17:27 111

原创 leetcode29两数相除

题目描述给定两个整数,被除数 dividend 和除数 divisor。将两数相除,要求不使用乘法、除法和 mod 运算符。返回被除数 dividend 除以除数 divisor 得到的商。整数除法的结果应当截去(truncate)其小数部分,例如:truncate(8.345) = 8 以及 truncate(-2.7335) = -2示例 1:输入: dividend = 10, divisor = 3输出: 3解释: 10/3 = truncate(3.33333..) = trunca

2021-10-13 12:27:28 67

原创 创建kafka单机伪集群

如上信息表示所生产的消息“Lei Li”为消息键,“Hello Kafka”为消息值。,因为kafka,zk都是依靠jdk,所以直接使用jdk的内置命令jps即可查看。

2021-10-11 16:47:56 103

原创 leetcode441排列硬币

题目描述这是一道简单题,为什么要记录这道题?1.为了提醒自己时刻考虑数据是否会产生溢出,以及怎么处理溢出,有许多小的skills2. 提醒自己数学理论知识在acm的应用提示:请大家先想一想这道题你会这么做,贴下题目链接,点击这里进行跳转你总共有 n 枚硬币,并计划将它们按阶梯状排列。对于一个由 k 行组成的阶梯,其第 i 行必须正好有 i 枚硬币。阶梯的最后一行 可能 是不完整的。给你一个数字 n ,计算并返回可形成 完整阶梯行 的总行数。输入:n = 5 输出:2 解释:因为第三行不完

2021-10-11 10:58:22 75

原创 leetcode352数据流拆分

题目信息给你一个由非负整数 a1, a2, ..., an 组成的数据流输入,请你将到目前为止看到的数字总结为不相交的区间列表。实现 SummaryRanges 类:SummaryRanges() 使用一个空数据流初始化对象。void addNum(int val) 向数据流中加入整数 val 。int[][] getIntervals() 以不相交区间 [starti, endi] 的列表形式返回对数据流中整数的总结。输入:["SummaryRanges", "addNum", "getIn

2021-10-10 16:38:46 115

原创 zk单机伪集群搭建

注意:本文基于zk伪集群localhost,127.0.0.1,本地IPcat /etc/hosts可以发现,操作系统将localhost 和 127.0.0.1绑定在了一起localhost和127.0.0.1都可以ping pong的方式来看本地ip/tcp是否正常localhost 和 127.0.0.1是不经网卡传输,不受网络防火墙和网卡相关的的限制。本地IP需要通过网络防火墙和网卡的限制,这也就是为什么用localhost 和 127.0.0.1就可以,但是使用本地IP不可以的原因z

2021-10-08 18:45:26 443

原创 leetcode600非连续1个数

数位DP对于「数位 DP」题,都存在「询问 [a, b](a 和 b 均为正整数,且 a < b)区间内符合条件的数值个数为多少」的一般形式,通常我们需要实现一个查询 [0, x]有多少合法数值的函数 int dp(int x),然后应用「容斥原理」求解出 [a, b]的个数:dp(b) - dp(a - 1)。暴力采用位运算,如果存在相邻1,那么无符号右移&本身!=0,那么说明不符合题意class Solution {public: int findIntegers(

2021-09-15 18:27:33 76

转载 2021-08-12

String s = "-1"; //此时输出的是10进制,并不是16进制System.out.println(bytes2hex01("-1".getBytes(StandardCharsets.UTF_8)));10进制转换为16进制 public static String bytes2hex01(byte[] bytes) { /** * 第一个参数的解释,记得一定要设置为1 * signum of the number (-1 for

2021-08-12 11:18:39 56

原创 leetcode146

codeTop题目public class LRUCache { class DLinkedNode { int key; int value; DLinkedNode prev; DLinkedNode next; public DLinkedNode() {} public DLinkedNode(int key, int value) { this.key = key

2021-05-23 11:03:39 44

原创 Java全排列

public class FullPermutation { private static List<String> ans = new LinkedList<>(); private static List<Character> res = new LinkedList<>(); public static void main(String[] args) { String s = "bba";

2021-05-23 11:02:50 45

空空如也

空空如也

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

TA关注的人

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