随笔分类 -  leetCode

摘要:原题链接 class Solution { public int[] plusOne(int[] digits) { int n = digits.length; List<Integer> list = new ArrayList<>(); int cnt = 0; for (int i = n 阅读全文
posted @ 2024-01-19 09:54 Eiffelzero 阅读(10) 评论(0) 推荐(0) 编辑
摘要:原题链接 class Solution { public String simplifyPath(String path) { // 用栈保存路径 Deque<String> stack = new LinkedList<>(); for (String s : path.split("/")) { 阅读全文
posted @ 2024-01-19 09:49 Eiffelzero 阅读(4) 评论(0) 推荐(0) 编辑
摘要:2331. 计算布尔二叉树的值 题解: DFS 深搜 class Solution { public boolean evaluateTree(TreeNode root) { switch (root.val) { case 0 : return false; case 1 : return tr 阅读全文
posted @ 2023-02-06 19:49 Eiffelzero 阅读(11) 评论(0) 推荐(0) 编辑
摘要:1129. 颜色交替的最短路径 题解: BFS 宽搜 用宽搜求最短路 public int[] shortestAlternatingPaths(int n, int[][] redEdges, int[][] blueEdges) { int[] res = new int[n]; res[0] 阅读全文
posted @ 2023-02-02 18:31 Eiffelzero 阅读(15) 评论(0) 推荐(0) 编辑
摘要:2325. 解密消息 题解 模拟 public String decodeMessage(String key, String message) { // 存映射 Map<Character, Character> map = new HashMap<>(); int i = 0; for (cha 阅读全文
posted @ 2023-02-01 16:30 Eiffelzero 阅读(16) 评论(0) 推荐(0) 编辑
摘要:2319. 判断矩阵是否是一个 X 矩阵 题解: 模拟 class Solution { public boolean checkXMatrix(int[][] grid) { int n = grid.length; for (int i = 0; i < n; i++) { for (int j 阅读全文
posted @ 2023-01-31 15:51 Eiffelzero 阅读(16) 评论(0) 推荐(0) 编辑
摘要:1669. 合并两个链表 題解: 模拟链表操作 /** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * ListNode() {} * ListNode(int 阅读全文
posted @ 2023-01-30 19:47 Eiffelzero 阅读(14) 评论(0) 推荐(0) 编辑
摘要:2315. 统计星号 题解: 按题意模拟 class Solution { public int countAsterisks(String s) { int n = s.length(); int res = 0; // 是否不在竖线对之间 boolean flag = true; for (in 阅读全文
posted @ 2023-01-29 10:57 Eiffelzero 阅读(19) 评论(0) 推荐(0) 编辑
摘要:1824. 最少侧跳次数 题解 dp 数组: dp[i] 表示 到 第i条赛道的最小侧跳次数 class Solution { public int minSideJumps(int[] obstacles) { int INF = (int) 0x3f3f3f3f; int len = obsta 阅读全文
posted @ 2023-01-21 13:30 Eiffelzero 阅读(5) 评论(0) 推荐(0) 编辑
摘要:1817. 查找用户活跃分钟数 题解 模拟: 用map存,map的key存用户id,value存该用户的操作的time列表(去重,可以用set) 统计res,遍历map,map的value为 该用户的操作时间list,用这个list的size 放到相应的res数组里(注意res的下标从1开始,所以要 阅读全文
posted @ 2023-01-20 14:48 Eiffelzero 阅读(27) 评论(0) 推荐(0) 编辑
摘要:2287. 重排字符形成目标字符串 class Solution { public int rearrangeCharacters(String s, String target) { int[] cnt = new int[30]; for (char c : s.toCharArray()) { 阅读全文
posted @ 2023-01-13 23:44 Eiffelzero 阅读(14) 评论(0) 推荐(0) 编辑
摘要:2283. 判断一个数的数字计数是否等于数位的值 class Solution { public boolean digitCount(String num) { int[] a = new int[10]; char[] chars = num.toCharArray(); int[] cnt = 阅读全文
posted @ 2023-01-11 03:35 Eiffelzero 阅读(14) 评论(0) 推荐(0) 编辑
摘要:2185. 统计包含给定前缀的字符串 class Solution { public int prefixCount(String[] words, String pref) { int res = 0; for (String word : words) { if (isEqual(word, p 阅读全文
posted @ 2023-01-08 20:28 Eiffelzero 阅读(12) 评论(0) 推荐(0) 编辑
摘要:1802. 有界数组中指定下标处的最大值 class Solution { public int maxValue(int n, int index, int maxSum) { int l = 1, r = (int) 1e9; while (l < r) { int mid = (l + r + 阅读全文
posted @ 2023-01-04 21:30 Eiffelzero 阅读(12) 评论(0) 推荐(0) 编辑
摘要:2042. 检查句子中的数字是否递增 class Solution { public boolean areNumbersAscending(String s) { char[] ch = s.toCharArray(); int pre = -1; for (int i = 0; i < ch.l 阅读全文
posted @ 2023-01-03 17:17 Eiffelzero 阅读(11) 评论(0) 推荐(0) 编辑
摘要:2351. 第一个出现两次的字母 class Solution { public char repeatedCharacter(String s) { char[] chars = s.toCharArray(); int[] f = new int[30]; for (int i = 0; i < 阅读全文
posted @ 2023-01-01 22:13 Eiffelzero 阅读(18) 评论(0) 推荐(0) 编辑
摘要:2032. 至少在两个数组中出现的值 class Solution { public List<Integer> twoOutOfThree(int[] nums1, int[] nums2, int[] nums3) { List<Integer> res = new ArrayList<>(); 阅读全文
posted @ 2022-12-30 00:01 Eiffelzero 阅读(13) 评论(0) 推荐(0) 编辑
摘要:1754. 构造字典序最大的合并字符串 题解: 每次从word1 和 word2 中取首字符 添加到merge字符串中,使得merge字符串字典序最大 比较word1 和 word2 的首字符,谁大用谁的 如果word1 和 word2 的首字符相等,此时需要比较word1 和 word2的字典序谁 阅读全文
posted @ 2022-12-24 12:41 Eiffelzero 阅读(28) 评论(0) 推荐(0) 编辑
摘要:[2011. 执行操作后的变量值] (https://leetcode.cn/problems/final-value-of-variable-after-performing-operations/description/) class Solution { public int finalVal 阅读全文
posted @ 2022-12-23 17:45 Eiffelzero 阅读(12) 评论(0) 推荐(0) 编辑
摘要:1753. 移除石子的最大得分 题解: 先将a,b,c 预处理为 a <= b <= c 当a + b <= c 时, 【ac】 和 【bc】 轮流取,直到a 和 b 为0 所以答案为 a + b 当a + b > c 时, 设【ac】取k1次, 【bc】取k2次,先将c取完,然后 再【ab】取 直 阅读全文
posted @ 2022-12-21 14:52 Eiffelzero 阅读(20) 评论(0) 推荐(0) 编辑

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