自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

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

原创 56.合并区间

56.合并区间class Solution { public int[][] merge(int[][] intervals) { Arrays.sort(intervals, (o1,o2) -> o1[0]-o2[0]); int[][] res = new int[intervals.length][2]; int idx = 0; for(int[] interval: intervals){ i

2022-05-27 16:25:43 54

原创 221.最大正方形

221.最大正方形class Solution { public int maximalSquare(char[][] matrix) { int n = matrix.length, m = matrix[0].length; int[][] dp = new int[n+1][m+1]; for(int i=1;i<=n;i++){ for(int j=1;j<=m;j++){

2022-05-27 15:15:36 57

原创 x的平凡根

69// 二分查找class Solution { public int mySqrt(int x) { long l=0, r=x; while(l < r){ long m = (l+r+1) >>> 1; if(m*m > x) r = m - 1; else l = m; //[l,r] } return (int)l;

2022-05-27 15:14:02 59

原创 删除排序链表

83.删除排序链表class Solution { public ListNode deleteDuplicates(ListNode head) { ListNode curr = head; while(curr!=null&&curr.next!=null){ if(curr.val == curr.next.val){ curr.next = curr.next.next;

2022-05-24 22:15:03 45

原创 56合并区间

56class Solution { public int[][] merge(int[][] intervals) { Arrays.sort(intervals, (o1,o2) -> o1[0]-o2[0]); int[][] res = new int[intervals.length][2]; int idx = 0; for(int[] interval: intervals){ if(idx

2022-05-23 09:26:48 59

原创 二叉树遍历

94中序class Solution { public List<Integer> inorderTraversal(TreeNode root) { ArrayList<Integer> res = new ArrayList<>(); order(root, res); return res; } private void order(TreeNode root, ArrayList res)

2022-05-22 19:28:29 51

原创 124二叉树最大路径和

124class Solution { int res; public int maxPathSum(TreeNode root) { res = Integer.MIN_VALUE; dfs(root); return res; } private int dfs(TreeNode root){ if(root == null) return 0; int left = dfs(root.le

2022-05-22 18:27:52 97

原创 经典接雨水

42// 暴力class Solution { public int trap(int[] height) { int res = 0; for(int i=1;i<height.length-1;i++){ int left = 0; for(int l = i; l>=0;l--){ left = Math.max(left, height[l]);

2022-05-22 02:22:05 64

原创 最长递增子序列 &个数

300.最长递增子序列// dp 无后序性class Solution { public int lengthOfLIS(int[] nums) { int len = nums.length; int[] dp = new int[len]; Arrays.fill(dp, 1); int res = 0; for(int i=0;i<len;i++){ for(int j=0;j&l

2022-05-21 21:46:44 103

原创 最长回文子串

5class Solution { public String longestPalindrome(String s) { int len = s.length(); if(len < 2) return s; boolean[][] dp = new boolean[len][len]; for (int i = 0; i < len; i++) { dp[i][i] = true;

2022-05-15 23:56:10 41

原创 岛屿问题系列

695 BFS DFS// BFSimport java.util.Deque;import java.util.LinkedList;class Solution { int[][] dirs; int temp; public int maxAreaOfIsland(int[][] grid) { dirs = new int[][]{{1,0},{-1,0},{0,1},{0,-1}}; int res = 0;

2022-05-15 01:07:39 58

原创 寻找旋转排序数组中的最小值

153要找最小值,就与最大值比较class Solution { public int findMin(int[] nums) { int left = 0, right = nums.length - 1; while(left < right){ int mid = (left + right) >>> 1; if(nums[mid] > nums[right]){

2022-05-13 23:08:54 38

原创 二分查找--单调性

33.搜索旋转排序数组class Solution { public int search(int[] nums, int target) { int left = 0, right = nums.length - 1; while(left < right){ int mid = (left + right) >>> 1; if(nums[mid] == target) return mid;

2022-05-13 22:02:41 113

原创 环形链表.

141.环形链表public class Solution { public boolean hasCycle(ListNode head) { if(head == null) return false; ListNode slow = head; ListNode fast = head; while(fast!=null&&fast.next!=null){ fast = fast.nex

2022-05-13 21:21:40 38

原创 有效的括号

20.有效的括号class Solution { public boolean isValid(String s) { HashMap<Character, Character> map = new HashMap<>(); map.put(')', '('); map.put(']', '['); map.put('}', '{'); char[] chars = s.toCharArray(

2022-05-13 20:54:30 39

原创 二叉树的层序遍历

102// 层序遍历 递归class Solution { List<List<Integer>> res; public List<List<Integer>> levelOrder(TreeNode root) { res = new ArrayList<>(); if(root == null) return res; dfs(root, 1); return

2022-05-13 20:15:32 43

原创 合并有序链表

21.合并两个有序链表class Solution { public ListNode mergeTwoLists(ListNode list1, ListNode list2) { ListNode dummy = new ListNode(0); ListNode pre = dummy; while(list1!=null&&list2!=null){ if(list1.val < list2.va

2022-05-13 19:33:37 156

原创 最大子数组和及其变种延申

53.最大子数组和//dpclass Solution { public int maxSubArray(int[] nums) { int[] dp = new int[nums.length + 1]; int res = Integer.MIN_VALUE; for(int i = 1; i <= nums.length; i++){ dp[i] = Math.max(nums[i-1], dp[i-1] + nums[i-1]); res = Math.ma

2022-05-13 15:27:22 146

原创 堆排序算法

912.排序数组class Solution { public int[] sortArray(int[] nums) { for(int i = nums.length/2 - 1; i >= 0; i--){ heapAdjust(i, nums.length, nums); } for(int i = nums.length - 1; i >= 1; i--){ int temp = nums[0]; nums[0] = nums[i];

2022-05-13 13:47:12 63

原创 数组中逆序数对(归并排序)

剑指offer 51完全就是归并排序分治思想的体现,在合并过程中,计算逆序对public class Solution { int[] temp; public int reversePairs(int[] nums) { temp = new int[nums.length]; return mergesort(0, nums.length - 1, nums); } private int mergesort(int left, int right

2022-05-13 02:44:33 61

原创 归并排序~

912.排序数组归并排序int[] temp;public int[] sortArray(int[] nums) { temp = new int[nums.length]; mergesort(0, nums.length - 1, nums); return nums;}private void mergesort(int left, int right, int[] nums){ if(left >= right) return; int mid = (left + rig

2022-05-13 00:55:23 54

原创 快排...

912.排序数组class Solution { public int[] sortArray(int[] nums) { quicksort(0, nums.length - 1, nums); return nums; } private void quicksort(int left, int right, int[] nums){ if(left >= right) return; int j = lef

2022-05-12 23:04:38 27

原创 反转链表加强

25.K个一组反转链表public ListNode reverseKGroup(ListNode head, int k) { ListNode dummy = new ListNode(0, head); ListNode pre = dummy; ListNode end = dummy; while(end.next != null){ for(int i = 0; i < k && en

2022-05-12 21:16:59 57

原创 滑动窗口困难

76.最小覆盖子串class Solution { public String minWindow(String s, String t) { if (s == null || s.length() == 0 || t == null || t.length() == 0) { return ""; } int[] need = new int[128]; // 包含大小写字母 //记录需要的字符的个数

2022-05-12 16:18:59 39

原创 无重复最长字串 + 进阶

3.无重复最长字串// 滑动窗口 + Hashmap记录public int lengthOfLongestSubstring(String s) { HashMap<Character, Integer> menu = new HashMap<>(); int res = 0, left = 0; for(int i = 0; i< s.length(); i++){ if(menu.containsKey(s.charAt(i))

2022-05-12 14:53:53 43

原创 反转链表Ⅰ、Ⅱ(递归&迭代)

206.反转链表// 迭代public ListNode reverseList(ListNode head){ ListNode pre = null; ListNode next; while(head!=null){ next = head.next; head.next = pre; pre = head; head = next; } return pre;}// 递归public ListNode reverseList(ListNode head){ i

2022-05-12 14:13:33 72

原创 实现数据结构(列表、队列、栈等)

707.设计链表在链表类中实现这些功能:get(index):获取链表中第 index 个节点的值。如果索引无效,则返回-1。addAtHead(val):在链表的第一个元素之前添加一个值为 val 的节点。插入后,新节点将成为链表的第一个节点。addAtTail(val):将值为 val 的节点追加到链表的最后一个元素。addAtIndex(index,val):在链表中的第 index 个节点之前添加值为 val 的节点。如果 index 等于链表的长度,则该节点将附加到链表的末尾。如果

2022-05-11 20:22:41 54

原创 删除链表元素

203移除链表元素class Solution { public ListNode removeElements(ListNode head, int val) { ListNode dummy = new ListNode(0, head); ListNode curr = head; ListNode pre = dummy; ListNode next; while(curr != null){

2022-05-10 22:38:29 232

原创 模拟法---螺旋矩阵

模拟法59螺旋矩阵Ⅱclass Solution { public int[][] generateMatrix(int n) { int l = 0, r = n - 1, t = 0, b = n - 1; int[][] mat = new int[n][n]; int num = 1, tar = n * n; while(num <= tar){ for(int i = l; i <=

2022-05-10 20:47:19 58

原创 滑动窗口模板题

提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档文章目录[滑动窗口 209 长度最小的子数组](https://leetcode.cn/problems/minimum-size-subarray-sum/)滑动窗口 209 长度最小的子数组给定一个含有 n 个正整数的数组和一个正整数 target 。找出该数组中满足其和 ≥ target 的长度最小的 连续子数组 [num, num+1, …, num-1, num] ,并返回其长度。如果不存在符合条件的子数组,返回 0 。.

2022-05-10 20:03:26 123 1

空空如也

空空如也

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

TA关注的人

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