uacs2024

导航

上一页 1 2 3 4 5 6 ··· 26 下一页

2025年11月21日 #

leetcode14. 最长公共前缀

摘要: 14. 最长公共前缀 注意,这是公共前缀,是从字符串第一个符号开始的,不是子串。 法一:横向扫描。自己先写的。 class Solution { public String longestCommonPrefix(String[] strs) { int len = strs.length; if( 阅读全文

posted @ 2025-11-21 21:13 ᶜʸᵃⁿ 阅读(6) 评论(0) 推荐(0)

2025年11月14日 #

leetcode36. 有效的数独

摘要: 36. 有效的数独 法一:自己写的HashSet,惊天四循环 您的代码通过三个独立的循环分别检查行、列和3×3宫格的有效性,逻辑清晰且易于理解。但主要问题在于: ••效率较低:进行了三次遍历(行、列、宫格),时间复杂度为O(3×81)=O(243),而最优解可一次遍历完成 ••冗余操作:每个循环都创 阅读全文

posted @ 2025-11-14 16:46 ᶜʸᵃⁿ 阅读(12) 评论(0) 推荐(0)

2025年11月13日 #

leetcode6. Z 字形变换

摘要: 6. Z 字形变换 法一:一开始自己写的史山代码. class Solution { public String convert(String s, int numRows) { if(numRows == 1) return s; ArrayList<char[]> zConvert = new 阅读全文

posted @ 2025-11-13 22:31 ᶜʸᵃⁿ 阅读(11) 评论(0) 推荐(0)

leetcode73. 矩阵置零

摘要: 73. 矩阵置零 法一:和零的数量相关的额外数组 202209写的c++代码 class Solution { public: void setZeroes(vector<vector<int>>& matrix) { int size1=matrix.size(),size2=matrix[0]. 阅读全文

posted @ 2025-11-13 15:04 ᶜʸᵃⁿ 阅读(4) 评论(0) 推荐(0)

2025年11月11日 #

leetcode289. 生命游戏

摘要: 289. 生命游戏 注意,更新要基于原状态更新,不是基于新状态的部分更新 法一:额外数组。对于边界,全部视为0。第一次通过的代码。 class Solution { public void gameOfLife(int[][] board) { int m = board.length,n = bo 阅读全文

posted @ 2025-11-11 22:06 ᶜʸᵃⁿ 阅读(7) 评论(0) 推荐(0)

2025年11月3日 #

leetcode55. 跳跃游戏 45. 跳跃游戏 II

摘要: 55. 跳跃游戏 45. 跳跃游戏 II 法一:我写的第一份通过的代码,问题在于重复更新浪费不少时间,内层循环可能会重复更新许多已经确定不是最优解的位置。 class Solution { public int jump(int[] nums) { int n = nums.length; int[ 阅读全文

posted @ 2025-11-03 21:31 ᶜʸᵃⁿ 阅读(18) 评论(0) 推荐(0)

13. 罗马数字转整数

摘要: 13. 罗马数字转整数 我写的原始代码,不够优雅。 class Solution { public int romanToInt(String s) { char[] sChar = s.toCharArray(); int res = 0,n = s.length(); HashMap<Chara 阅读全文

posted @ 2025-11-03 17:13 ᶜʸᵃⁿ 阅读(9) 评论(0) 推荐(0)

2025年10月31日 #

leetcode274. H 指数

摘要: 274. H 指数 自己写的先排序后反向遍历 class Solution { public int hIndex(int[] citations) { int n = citations.length; Arrays.sort(citations); if(citations[0] >= n) r 阅读全文

posted @ 2025-10-31 14:33 ᶜʸᵃⁿ 阅读(6) 评论(0) 推荐(0)

2025年10月28日 #

leetcode88. 合并两个有序数组

摘要: 88. 合并两个有序数组 法一:第一时间想到的额外空间 class Solution { public void merge(int[] nums1, int m, int[] nums2, int n) { int i = 0,j = 0; int[] res = new int[m + n]; 阅读全文

posted @ 2025-10-28 22:06 ᶜʸᵃⁿ 阅读(12) 评论(0) 推荐(0)

2025年10月23日 #

leetcode1. 两数之和、15. 三数之和、18. 四数之和

摘要: 1. 两数之和 注意,这个要返回的是对应数字的下标。 2022/09的C++代码 class Solution { public: vector<int> twoSum(vector<int>& nums, int target) { int size=nums.size(); unordered_ 阅读全文

posted @ 2025-10-23 22:06 ᶜʸᵃⁿ 阅读(8) 评论(0) 推荐(0)

上一页 1 2 3 4 5 6 ··· 26 下一页