自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

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

原创 leetcode_84_柱状图中最大的矩形

class Solution { public static int largestRectangleArea(int[] heights) { int length = heights.length; if (length == 0) return 0; if (length == 1) return heights[0]; int[] rightMin = new int[length]; int[] leftMin = new int[length];..

2020-08-08 10:58:47 127

原创 leetcode_162_寻找峰值

class Solution { public int findPeakElement(int[] nums) { int l=0; int r=nums.length-1; while(l<r){ int mid=(l+r)>>1; if(nums[mid]<nums[mid+1]){ l=mid+1; }else{ .

2020-08-07 00:56:09 114

原创 leetcode_74_搜索二维矩阵@@二分

class Solution { public boolean searchMatrix(int[][] matrix, int target) { if (matrix.length == 0) return false; int j = matrix[0].length - 1; int i = 0; while (i < matrix.length && j >= 0) { if (matrix[i][j] == target) { .

2020-08-06 23:37:53 161

原创 leetcode_36_有效的数独@@暴力

class Solution { public boolean isValidSudoku(char[][] board) { for (int i = 0; i < 9; i++) { int[] rows = new int[10]; for (int j = 0; j < 9; j++) { if (board[i][j] == '.') continue; int parseInt = board[i][j] - '0'; ...

2020-08-06 16:31:28 92

原创 leetcode_34_在排序数组中查找元素的第一个和最后一个位置@@二分

class Solution { public int[] searchRange(int[] nums, int target) { int[] arr = { -1, -1 }; if (nums.length == 0) return arr; int l = 0; int r = nums.length - 1; //找到右端点 while (l < r) { int mid = (l + r + 1) >> 1; if (nu.

2020-08-06 14:47:41 87

原创 leetcode_33_搜索旋转排序数组

class Solution { public int search(int[] nums, int target) { if(nums.length==0) return -1; if(nums.length==1) return nums[0]==target?0:-1; int l = 0; int r = nums.length - 1; while (l < r) { int mid = (l + r+1) >&.

2020-08-06 11:49:35 69

原创 leetcode_32_最长有效括号

class Solution { public int longestValidParentheses(String s) { char[] charArray = s.toCharArray(); if (charArray.length == 0 || charArray.length == 1) return 0; int[] dp = new int[charArray.length]; int max = 0; for (int i = 1; i < dp..

2020-08-06 00:05:55 72

原创 leetcode_31_下一个排列

class Solution { public void nextPermutation(int[] nums) { if (nums.length == 1) return; int k = nums.length - 1; // 从后往前找到一个非严格升序的子序列 while (k > 0 && nums[k - 1] >= nums[k]) k--; if (k == 0) { reverse(nums, 0, nums.l.

2020-08-05 20:07:24 66

原创 十大排序

MergeSort //将[begin,end)部分排序 private void sort(int[] arr,int begin, int end) { if((end-begin)<2) return ; int mid=(begin+end)>>1; sort(arr,0,mid); sort(arr,mid,end); merge(arr,begin, mid, end); }我们发现如果左边先结束的话,右边的数组剩下的元素自动就..

2020-08-05 16:06:35 140

原创 leetcode_75_颜色分类

class Solution { public void sortColors(int[] nums) {//三指针 int l = 0; int r = nums.length - 1; int i=0; while(i <= r) { if(nums[i]==0) { swap(nums, i++, l++); }else if(nums[i]==2) { swap(nums, i, r--); }else { i++; .

2020-08-04 17:41:16 88

原创 leetcode_88_合并两个有序数组

class Solution { public static void merge(int[] nums1, int m, int[] nums2, int n) { int i=m-1; int j=n-1; int k=nums1.length-1; while(i>=0&&j>=0) { nums1[k--]=nums1[i]<=nums2[j]?nums2[j--]:nums1[i--]; } if(i<0) { .

2020-08-04 15:57:55 53

原创 leetcode_42_接雨水

public int trap(int[] height) {//双指针 if(height.length==0||height==null||height.length==1||height.length==2) return 0; int[] rightMaxes=new int[height.length]; int lastIndex=height.length-2; for (int r = height.length-2; r >=0; r--) {..

2020-08-04 11:23:17 84

原创 leetcode_240_搜索二维矩阵 II

class Solution { public boolean searchMatrix(int[][] matrix, int target) { if(matrix.length==0) return false; int i=0; int j=matrix[0].length-1; //从右上角那个点搜索,左小下大的特性 while(i<matrix.length && j>=0) { if(matrix[i].

2020-08-04 09:10:33 65

原创 leetcode_167_两数之和 II - 输入有序数组

class Solution { //双指针 public int[] twoSum(int[] numbers, int target) { int l=0; int r=numbers.length-1; while(l<r) { if((numbers[l]+numbers[r])==target) { break; }else if((numbers[l]+numbers[r])<target) { l++; }.

2020-08-04 01:09:08 67

原创 leetcode_11_盛最多水的容器

class Solution { //双指针 public int maxArea(int[] height) { int l=0; int r=height.length-1; int max=0; while(l<r) { int minHeight=height[l]<=height[r]?height[l++]:height[r--]; max=Math.max(max, (r-l+1)*minHeight); } return ma.

2020-08-04 01:04:57 51

原创 leetcode_253_会议室 II

class Solution { public int minMeetingRooms(int[][] intervals) { if (intervals == null || intervals.length == 0) return 0; PriorityQueue<Integer> heap = new PriorityQueue<Integer>(); Arrays.sort(intervals, (o1, o2) -> o1[0] -.

2020-08-03 23:03:55 146

原创 leetcode_146_LRU缓存机制

public class LRUCache { private Map<Integer, Node> map; private int capacity; private Node first; private Node last; public LRUCache(int capacity) { map = new HashMap<>(capacity); this.capacity = capacity; first = new Node(); la.

2020-08-03 18:39:17 73

原创 leetcode_59_螺旋矩阵 II

class Solution { public int[][] generateMatrix(int n) { if(n<=0) return new int[0][0]; int[][] res=new int[n][n]; int top=0; int bottom=n-1; int left=0; int right=n-1; int flag=1; .

2020-08-03 16:12:38 83

原创 leetcode_54_螺旋矩阵

class Solution { public List<Integer> spiralOrder(int[][] matrix) { if(matrix==null) return null; List<Integer> res=new ArrayList<Integer>(); if(matrix.length==0) return res; int top=0; int bott.

2020-08-03 16:02:23 76

原创 剑指 Offer_62_圆圈中最后剩下的数字

class Solution { public int lastRemaining(int n, int m) { int res=0; for(int i=2;i<=n;i++){ res=(res+m)%i; } return res; }}class Solution { public int lastRemaining(int n, int m) { retu.

2020-08-03 14:41:09 98

原创 leetcode_50_Pow(x, n)

class Solution { public double myPow(double x, int n) { if(n==0) return 1; if(n==-1) return 1/x; boolean odd=(n&1)==1; double half=myPow(x,n>>1); half*=half; return odd?half*x:half; }}cl.

2020-08-03 14:08:40 69

原创 leetcode_15_三数之和@@数组(双指针)

class Solution { public List<List<Integer>> threeSum(int[] nums) { List<List<Integer>> list=new ArrayList<List<Integer>>(); if(nums.length<3) return list; Arrays.sort(nums); int l.

2020-07-28 19:26:36 43

原创 leetcode_216_组合总和 III@@dfs

class Solution {int tempSum;List<List<Integer>> list=new ArrayList<>();List<Integer> tempList=new ArrayList<>(); public List<List<Integer>> combinationSum3(int k, int n) { dfs(0,1,n,k); re.

2020-07-28 14:56:58 59

原创 leetcode_40_组合总和 II@@dfs

class Solution { int sum; int[] nums; int tempSum; List<List<Integer>> list=new ArrayList<List<Integer>>(); List<Integer> tempList=new ArrayList<Integer>(); public List<List<Integer>> combinati.

2020-07-28 14:55:50 79

原创 leetcode_39_组合总和@@dfs

class Solution { int sum; int[] nums; int tempSum; List<List<Integer>> list=new ArrayList<List<Integer>>(); List<Integer> tempList=new ArrayList<Integer>(); public List<List<Integer>> combinat.

2020-07-28 14:21:52 48

原创 leetcode_113_路径总和 II@@dfs

class Solution { int sum; int tempSum=0; boolean flag; List<List<Integer>> list=new ArrayList<>(); List<Integer> tempList=new ArrayList<>(); public List<List<Integer>> pathSum(TreeNode .

2020-07-27 21:47:49 87

原创 leetcode_112_路径总和@@dfs

class Solution { int sum; int tempSum=0; boolean flag; List<List<Integer>> list=new ArrayList<>(); List<Integer> tempList=new ArrayList<>(); public boolean hasPathSum(TreeNode root, int sum) { .

2020-07-27 21:43:23 62

原创 leetcode_22_括号生成@@dfs

class Solution { int count; int leftCount; int rightCount; char[] str; List<String> list=new ArrayList<String>(); public List<String> generateParenthesis(int n) { if(n==0) return new ArrayList<String>(); coun.

2020-07-27 19:59:09 79

原创 leetcode_47_全排列 II@@dfs

int[] nums; boolean[] seleectedArr; HashSet<List<Integer>> list = new HashSet<List<Integer>>(); int[] tempArr; public List<List<Integer>> permuteUnique(int[] nums) { if (nums.length == 0) return new ArrayList..

2020-07-27 18:28:55 76

原创 leetcode_46_全排列@@dfs

int[] nums; boolean[] seleectedArr; //HashSet<Integer> selectedNum=new HashSet<Integer>(); List<List<Integer>> list=new ArrayList<List<Integer>>(); //List<Integer> tempList=new ArrayList<Integer>();...

2020-07-27 15:57:04 51

原创 leetcode_17_电话号码的字母组合@@dfs

自己乱写的可能是bfsclass Solution { private static String[] getFromnum(int num) { if (num < 7) { String[] ss = new String[3]; int flag = 97 + (num - 2) * 3; ss[0] = (char) flag + ""; ss[1] = ((char) (flag + 1)) + ""; ss[2] = ((char) (flag.

2020-07-26 23:14:11 61

原创 leetcode_333_最大 BST 子树@@二叉树

自顶向下 TreeNode prev; private boolean isBST(TreeNode root) { if(root==null) return true; boolean left = isBST(root.left); if(prev!=null&&prev.val>=root.val) { //>=这题节点有可能相同,相同节点不是BST return false; } prev=.

2020-07-26 18:09:33 156

原创 leetcode_99_恢复二叉搜索树

二叉搜索树中的两个节点被错误地交换。请在不改变其结构的情况下,恢复这棵树。进阶:使用 O(n) 空间复杂度的解法很容易实现。你能想出一个只使用常数空间的解决方案吗?递归实现中序遍历/** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode() {} * Tr

2020-07-26 00:41:58 79

原创 leetcode_5_最长回文子串

给定一个字符串 s,找到 s 中最长的回文子串。你可以假设 s 的最大长度为 1000。示例 1:输入: “babad”输出: “bab”注意: “aba” 也是一个有效答案。示例 2:输入: “cbbd”输出: “bb”来源:力扣(LeetCode)链接:https://leetcode-cn.com/problems/longest-palindromic-substring暴力尝试,肯定是超时的,通过大概一半测试用例class Solution { public Stri

2020-07-25 00:08:17 79

原创 leetcode_115_不同的子序列@@dp

给定一个字符串 S 和一个字符串 T,计算在 S 的子序列中 T 出现的个数。一个字符串的一个子序列是指,通过删除一些(也可以不删除)字符且不干扰剩余字符相对位置所组成的新字符串。(例如,“ACE” 是 “ABCDE” 的一个子序列,而 “AEC” 不是)题目数据保证答案符合 32 位带符号整数范围。来源:力扣(LeetCode)链接:https://leetcode-cn.com/problems/distinct-subsequences链接: link.首先就是暴力尝试 public s

2020-07-23 20:00:52 68

原创 swagger简单使用

与springBoot集成1.导入相关依赖<!-- https://mvnrepository.com/artifact/io.springfox/springfox-swagger2 --> <dependency> <groupId>io.springfox</groupId> <artifactId>spring...

2020-03-11 18:59:03 215

原创 heapSort题目

已知一个几乎有序的数组, 几乎有序是指, 如果把数组排好顺序的话, 每个元素移动的距离可以不超过k, 并且k相对于数组来说比较小。 请选择一个合适的排序算法针对这个数据进行排序。public class Code04_SortArrayDistanceLessK { public static void lessK(int[] arr,int K){ Priorit...

2019-12-07 16:20:41 133

原创 折纸问题

折纸问题请把一段纸条竖着放在桌子上, 然后从纸条的下边向上方对折1次, 压出折痕后展开。此时折痕是凹下去的, 即折痕突起的方向指向纸条的背面。如果从纸条的下边向上方连续对折2次, 压出折痕后展开, 此时有三条折痕, 从上到下依次是下折痕、 下折痕和上折痕。给定一个输入参数N, 代表纸条都从下边向上方连续对折N次。请从上到下打印所有折痕的方向。例如:N=1时, 打印: down N=...

2019-12-06 15:50:33 89

空空如也

空空如也

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

TA关注的人

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