avatar
文章
590
标签
104
分类
17

首页
归档
标签
分类
友链
日志
byu_rself
搜索
首页
归档
标签
分类
友链
日志

byu_rself

LC.P2600[K件物品的最大和]
发表于2023-07-05|更新于2023-07-05|LeetCode|贪心
LC.P2600[K件物品的最大和] 方法一:贪心1234567class Solution { public int kItemsWithMaximumSum(int numOnes, int numZeros, int numNegOnes, int k) { if (numOnes >= k) return k; else if (numOnes + numZeros >= k) return numOnes; else return numOnes - (k - numOnes - numZeros); }} 时间复杂度:$O(1)$ 空间复杂度:$O(1)$
LC.P65[有效数字]
发表于2023-07-04|更新于2023-07-04|LeetCode|字符串•模拟
LC.P65[有效数字] 方法一:模拟123456789101112131415161718192021222324252627282930313233343536373839404142class Solution { public boolean isNumber(String s) { char[] cs = s.toCharArray(); int index = -1, n = cs.length; for (int i = 0; i < n; ++i) { if (cs[i] == 'e' || cs[i] == 'E') { if (index == -1) index = i; else return false; } } boolean ans = true; if (in ...
LC.P2679[矩阵中的和]
发表于2023-07-04|更新于2023-07-04|LeetCode|数组•排序
LC.P2679[矩阵中的和] 方法一:暴力123456789101112131415161718192021222324class Solution { public int matrixSum(int[][] nums) { int ans = 0, m = nums.length, n = nums[0].length; int[] score = new int[m]; for (int i = 0; i < n; ++i) { for (int j = 0; j < m; ++j) { int maxIndex = 0; for (int k = 0; k < n; ++k) { if (nums[j][maxIndex] < nums[j][k]) { maxIndex = k; ...
LC.P393[UTF-8编码验证]
发表于2023-07-03|更新于2023-07-03|LeetCode|模拟•位运算
LC.P393[UTF-8编码验证] 方法一:模拟12345678910111213141516171819class Solution { public boolean validUtf8(int[] data) { int n = data.length; for (int i = 0; i < n; ) { int t = data[i], j = 7; while (j >= 0 && (((t >> j) & 1) == 1)) --j; int cnt = 7 - j; if (cnt == 1 || cnt > 4) return false; if (i + cnt - 1 >= n) return false; for (int k = i + 1; k < i + cnt; ++k) { ...
LC.P385[迷你语法分析器]
发表于2023-07-03|更新于2023-07-03|LeetCode|栈•模拟
LC.P385[迷你语法分析器] 方法一:栈123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172/** * // This is the interface that allows for creating nested lists. * // You should not implement it, or speculate about its implementation * public interface NestedInteger { * // Constructor initializes an empty nested list. * public NestedInteger(); * * // Constructor initializes a single integer. * public NestedInte ...
LC.P284[顶端迭代器]
发表于2023-07-03|更新于2023-07-03|LeetCode|模拟
LC.P284[顶端迭代器] 方法一:模拟12345678910111213141516171819202122232425262728293031// Java Iterator interface reference:// https://docs.oracle.com/javase/8/docs/api/java/util/Iterator.htmlclass PeekingIterator implements Iterator<Integer> { Iterator<Integer> iterator; Integer next; public PeekingIterator(Iterator<Integer> iterator) { // initialize any member here. this.iterator = iterator; if (iterator.hasNext()) next = iterator.next(); } ...
LC.P445[两数相加II]
发表于2023-07-03|更新于2023-07-03|LeetCode|栈•链表•迭代
LC.P445[两数相加II] 方法一:栈+迭代1234567891011121314151617181920212223242526272829303132333435/** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * ListNode() {} * ListNode(int val) { this.val = val; } * ListNode(int val, ListNode next) { this.val = val; this.next = next; } * } */class Solution { public ListNode addTwoNumbers(ListNode l1, ListNode l2) { Deque<Integer> s1 = new ...
LC.P400[第N位数字]
发表于2023-07-02|更新于2023-07-03|LeetCode|数学•模拟
LC.P400[第N位数字] 方法一:模拟12345678910111213141516171819202122232425class Solution { // 基本规律: // [1, 9] 有9 * 1个数字 => 9 * 1 * 1 => 9 * 10^0 * 1 // [10, 99] 有90 * 2个数字 => 9 * 10 * 2 => 9 * 10^1 * 2 // [100, 999] 有900 * 3个数字 => 9 * 100 * 3 => 9 * 10^2 * 3 // [1000, 9999] 有9000 * 4个数字 => 9 * 1000 * 4 => 9 * 10^3 * 4 // => 9 * 10^(n-1) * n // ... public int findNthDigi ...
LC.P166[分数到小数]
发表于2023-07-02|更新于2023-12-15|LeetCode|数学•模拟
LC.P166[分数到小数] 方法一:模拟1234567891011121314151617181920212223242526272829class Solution { public String fractionToDecimal(int numerator, int denominator) { long a = numerator, b = denominator; if (a % b == 0) return String.valueOf(a / b); StringBuilder builder = new StringBuilder(); // 其中一个数为负数,先加负号 if (a * b < 0) { builder.append('-'); a = Math.abs(a); b = Math.abs(b); } // 计算小数点前的 ...
LC.P2[两数相加]
发表于2023-07-02|更新于2023-07-03|LeetCode|链表•递归•迭代
LC.P2[两数相加] 方法一:递归123456789101112131415161718192021222324252627282930/** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * ListNode() {} * ListNode(int val) { this.val = val; } * ListNode(int val, ListNode next) { this.val = val; this.next = next; } * } */class Solution { public ListNode addTwoNumbers(ListNode l1, ListNode l2) { return dfs(l1, l2, 0); } private Li ...
1…343536…59
avatar
byu_rself
努力努力!
文章
590
标签
104
分类
17
Follow Me
最新文章
LC.P416[分割等和子集]2025-04-07
LC.P2874[有序三元组中的最大值II]2025-04-02
LC.P3128[直角三角形]2024-08-02
LCP.P40[心算挑战]2024-08-01
LC.P3115[质数的最大距离]2024-07-02
分类
  • LeetCode546
    • LCP4
    • LCR13
    • 剑指Offer13
    • 面试题2
  • Linux3
  • 后端9
    • CompletableFuture1
标签
GitDFSGolang动态规划记忆化搜索字符串栈数学数组哈希表滑动窗口链表递归图BFS多源BFS双指针树子数组前缀和前缀树字典树Trie子序列区间DP递推模拟枚举字符串哈希二分查找贪心排序负二进制回溯二叉树状态压缩子串迭代随机化后缀和
归档
  • 四月 20252
  • 八月 20242
  • 七月 20241
  • 五月 20243
  • 四月 20242
  • 三月 202410
  • 二月 202410
  • 一月 202414
网站资讯
文章数目 :
590
已运行时间 :
本站总字数 :
289.3k
本站访客数 :
本站总访问量 :
最后更新时间 :
©2023 - 2025 By byu_rself
框架 Hexo|主题 Butterfly
Hi, welcome to my blog!
搜索
数据库加载中