Passion and Patience

Work Hard, Play Hard

导航

2024年3月17日 #

Leecode 合并两个有序数组

摘要: Day 2 刷题 未ac,力扣官方解题思路:利用双指针来把数组更新重载到新数组sorted内 class Solution { public void merge(int[] nums1, int m, int[] nums2, int n) { int p1 = 0, p2 = 0; // ref 阅读全文

posted @ 2024-03-17 22:33 安静的聆 阅读(3) 评论(0) 推荐(0) 编辑

Leecode 二叉树的前序遍历

摘要: Day2 刷题 我的思路:用数组list存储遍历结果,利用ArrayList的方法实现嵌套! import java.util.*; class Solution { // defining an arraylist public List<Integer> preorderTraversal(Tr 阅读全文

posted @ 2024-03-17 20:14 安静的聆 阅读(4) 评论(0) 推荐(0) 编辑

Leecode 搜索插入位置

摘要: Day 2 刷题 我的思路:利用二分法解决问题,不过由于情况没有好好分类,以及循环判定条件不合适,会出现超出运行时间的bug。 class Solution { public int searchInsert(int[] nums, int target) { int length = nums.l 阅读全文

posted @ 2024-03-17 17:43 安静的聆 阅读(6) 评论(0) 推荐(0) 编辑

Leecode 最长公共前缀

摘要: Day 1 刷题 此题没有写出来,仅附上力扣官方代码: class Solution { public String longestCommonPrefix(String[] strs) { if(strs == null||strs.length ==0){ return ""; } String 阅读全文

posted @ 2024-03-17 17:09 安静的聆 阅读(8) 评论(0) 推荐(0) 编辑

Leecode 将罗马数字转换为整型

摘要: Day 1 刷题 我的解题思路利用罗马数字与整型的转换规律,利用哈希表来生成键值对。 class Solution { public int romanToInt(String s) { int sum = 0; HashMap<Character, Integer> RomanInt = new 阅读全文

posted @ 2024-03-17 16:57 安静的聆 阅读(6) 评论(0) 推荐(0) 编辑

Leecode 回文数

摘要: Day1 刷题 我的解题思路是将整型转换为字符串,利用中心对称来判断是否是回文数。时间复杂度为\(\mathcal{O}(n)\),因为for循环的存在。 class Solution { public boolean isPalindrome(int x) { String y = String. 阅读全文

posted @ 2024-03-17 15:01 安静的聆 阅读(8) 评论(0) 推荐(0) 编辑

Leecode 求两数之和

摘要: Day1 刷题 我的解题思路是按照第一个元素往后排,不重复的找相加的组合,判断是否为target值,时间复杂度较高,为\(\mathcal{O}(n^2)\)。 class Solution { public int[] twoSum(int[] nums, int target) { int fl 阅读全文

posted @ 2024-03-17 14:42 安静的聆 阅读(4) 评论(0) 推荐(0) 编辑