自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

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

原创 147. 对链表进行插入排序

class Solution { public ListNode insertionSortList(ListNode head) { if (head == null) { return head; } ListNode dummy = new ListNode(0, head); ListNode lastSorted = head, current = head.next; while (c

2021-11-30 23:20:01 216

原创 5941. 找出知晓秘密的所有专家(力扣周赛2021.11.28——Java解法,哈希表)

class Solution { public List<Integer> findAllPeople(int n, int[][] meetings, int firstPerson) { //将二维数组传入比较器中对会议时间点排序 Arrays.sort(meetings, new Comparator<int[]>() { @Override public int compare(int[.

2021-11-28 15:38:43 486

原创 LeetCode刷题笔记(JAVA)——328. 奇偶链表

构建两个假头和两个指针,然后奇数位置节点挂在dummy后面,偶数节点位置挂在dummy2后面/** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * ListNode() {} * ListNode(int val) { this.val = val; } * ListNode(int val, ListNode n.

2021-11-26 20:20:58 417

原创 LeetCode刷题笔记(JAVA)——118. 杨辉三角(动态规划)

执行用时:0 ms, 在所有 Java 提交中击败了100.00%的用户内存消耗:36.5 MB, 在所有 Java 提交中击败了8.28%的用户class Solution { public List<List<Integer>> generate(int numRows) { if (numRows == 0) { List<List<Integer>> result = new ArrayList&lt

2021-11-25 19:32:14 239

原创 LeetCode刷题笔记(JAVA)——209. 长度最小的子数组(滑动窗口)

class Solution { public int minSubArrayLen(int target, int[] nums) { int minLength = Integer.MAX_VALUE; int length = nums.length; int sum = 0, start = 0, end = 0; if (length == 0) { return 0; }

2021-11-25 18:33:47 323

原创 LeetCode刷题笔记(JAVA)——151. 翻转字符串里的单词

执行用时:7 ms, 在所有 Java 提交中击败了58.82%的用户内存消耗:38.6 MB, 在所有 Java 提交中击败了33.35%的用户通过测试用例:58 / 58class Solution { public String reverseWords(String s) { s = s.trim(); Deque<String> deque = new LinkedList<>(); int length = s

2021-11-25 00:36:10 351

原创 LeetCode刷题笔记(JAVA)——14. 最长公共前缀

class Solution { public String longestCommonPrefix(String[] strs) { int length = strs.length; int minLength = getMinLength(strs); StringBuilder stringBuilder = new StringBuilder(); for (int i = 0; i < minLength; ++i)

2021-11-24 12:10:53 209

原创 LeetCode刷题笔记(JAVA)——498. 对角线遍历

class Solution { public int[] findDiagonalOrder(int[][] mat) { if (mat == null || mat.length == 0 || mat[0].length == 0) { //空矩阵判定 return new int[0]; } int m = mat.length; //行 int n = mat[0].length; //列

2021-11-24 11:35:13 103

原创 LeetCode——数组和字符串——零矩阵(java解法)

class Solution { public void setZeroes(int[][] matrix) { int rows = matrix.length; int columns = matrix[0].length; HashMap<Integer, Integer> map1 = new HashMap<>(); HashMap<Integer, Integer> map2 = new.

2021-11-22 23:37:10 86

原创 LeetCode刷题笔记(JAVA)——48. 旋转图像

如果是顺时针旋转90°一定是先对角线翻转,再水平翻转如果是逆时针旋转90°一定是先水平翻转,再对角线翻转class Solution { public void rotate(int[][] matrix) { int length = matrix.length; int temp; for (int i = 0; i < length; ++i) { for (int j = i + 1; j < len

2021-11-22 22:39:58 70

原创 LeetCode刷题笔记(JAVA)——56. 合并区间

class Solution { public int[][] merge(int[][] intervals) { if (intervals.length == 0) { return new int[0][2]; } Arrays.sort(intervals, Comparator.comparingInt(interval -> interval[0])); //也可以用下面的匿名内部类表示,

2021-11-22 22:18:00 246

原创 LeetCode刷题笔记(JAVA)——234. 回文链表

解法一/** * 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; }

2021-11-19 20:01:13 107

原创 LeetCode刷题笔记(JAVA)——563. 二叉树的坡度

解法一先得到左右两个子节点的总和,再分情况递归class TreeNode { int val; TreeNode left; TreeNode right; TreeNode() { } TreeNode(int val) { this.val = val; } TreeNode(int val, TreeNode left, TreeNode right) { this.val = val;

2021-11-19 00:44:40 202

转载 LeetCode刷题笔记(JAVA)——43. 字符串相乘

第一行是j,第二行是iclass Solution { public String multiply(String num1, String num2) { if (num1.equals("0") || num2.equals("0")) { return "0"; } int length1 = num1.length(); int length2 = num2.length(); int.

2021-11-17 13:20:52 66

原创 LeetCode刷题笔记(JAVA)——042 接雨水

解法一:动态规划(复杂度较高)class Solution { public int trap(int[] height) { int n = height.length; if (n == 0) { return 0; } int[] leftMax = new int[n]; leftMax[0] = height[0]; for (int i = 1; i < n;

2021-11-16 16:04:15 414

转载 转载:JAVA面试题 String s = new String(“xyz“);产生了几个对象?

面试官Q1:请问String s = new String(“xyz”);产生了几个对象?对于这个Java面试题,老套路先上代码:public class StringTest { public static void main(String[] args){ String s1="Hello"; String s2="Hello"; String s3=new String("Hello"); System.out.println

2021-11-15 23:34:02 147

原创 LeetCode刷题笔记(JAVA)——039、040 组合总和、组合总和 II

回溯算法 + 剪枝Solution039class Solution { public List<List<Integer>> combinationSum(int[] candidates, int target) { int len = candidates.length; List<List<Integer>> res = new ArrayList<>(); if (len ==

2021-11-15 22:53:00 54

原创 LeetCode刷题笔记(JAVA)——037 解数独

数独求解 回溯算法class Solution { boolean[][] line = new boolean[9][9]; boolean[][] column = new boolean[9][9]; boolean[][][] block = new boolean[3][3][9]; boolean valid = false; List<int[]> spaces = new ArrayList<>(); public

2021-11-15 16:31:47 238

原创 LeetCode刷题笔记(JAVA)——025K 个一组翻转链表

K 个一组翻转链表给一个链表,每 k 个节点一组进行翻转,返回翻转后的链表。k 是一个正整数,它的值小于或等于链表的长度。如果节点总数不是 k 的整数倍,那么最后剩余的节点保持原有顺序。不能只是单纯的改变节点内部的值,而是需要实际进行节点交换。笨方法 ̄□ ̄||剪切链表→反转链表→拼接链表/** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next

2021-11-05 20:17:56 81

原创 LeetCode刷题笔记(JAVA)——005最长回文子串

005最长回文子串解法class Solution { public String longestPalindrome(String s) { int n = s.length(); boolean[][] dp = new boolean[n][n]; String result = ""; int j; for (int k = 0; k < n; k++) { for (int

2021-03-26 01:09:59 110

原创 KMP算法——字符串匹配问题(JAVA实现,动态规划求部分匹配值表,双指针实现KMP搜索)

KMP算法——字符串匹配问题(JAVA实现)部分匹配值的实现方式与尚硅谷韩顺平老师讲的一致,自己主要是对搜索算法进行了重写,仅供参考package KMP;import java.util.Arrays;public class KMPAlgorithm { public static void main(String[] args) { String str1 = "BBC ABCDAB ABCDABCDABDE"; String str2 = "C A

2021-02-19 17:31:09 432 4

空空如也

空空如也

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

TA关注的人

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