自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

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

原创 【经典】盛最多水的容器

一、题目力扣原题:https://leetcode-cn.com/problems/container-with-most-water/submissions/二、暴力class Solution { public int maxArea(int[] height) { if (null == height || 0 == height.length) { return 0; } int max = 0;

2020-05-23 15:25:47 299

原创 【链表】链表排序

一、题目力扣原题:https://leetcode-cn.com/problems/sort-list/二、归并排序/** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * ListNode(int x) { val = x; } * } */class Solution { public ListNode so

2020-05-23 13:11:17 516

原创 【经典】实现一个阻塞队列

import java.util.concurrent.locks.Condition;import java.util.concurrent.locks.Lock;import java.util.concurrent.locks.ReentrantLock;public class BlockingQueue<T> { /** * 对象池 */ private Object[] objs; /** * 容量 */.

2020-05-20 23:49:57 293

原创 【多线程】连续打印ABC

一、内置锁同步:synchronized 协作:Object # wait/notify/notifyAllpublic class PrintABC { /** * 打印锁,同一时刻仅有一个任务可以持有此锁 */ private static Object lock = new Object(); private static int state = 1; public static void main(String args[]) {

2020-05-20 23:08:55 227

原创 【排序】归并排序

import java.util.Arrays;import java.util.Random;public class MergeSort { public static void main(String args[]) { int[] array = fillArray(); split(array, 0, array.length - 1); System.out.println(Arrays.toString(array)); .

2020-05-20 21:44:08 127

原创 【多线程】双线程交替打印1至100

一、内置锁同步:synchronized 协作:Object # wait/notify/notifyAllpublic class PrintNumber { /** * 打印锁,同一时刻仅有一个任务可以持有此锁 */ private static Object lock = new Object(); /** * 计数器 */ private static int counter = 1; /**

2020-05-17 22:40:58 2453

原创 【排序】快速排序

public class QuickSort { private static int[] fillArray() { Random random = new Random(); int[] array = new int[100]; for (int i = 0; i < array.length; i++) { array[i] = random.nextInt(10000); } .

2020-05-17 19:40:32 226

原创 【动态规划】最长上升子序列

一、题目力扣原题:https://leetcode-cn.com/problems/longest-increasing-subsequence/二、动态规划class Solution { public int lengthOfLIS(int[] nums) { if (null == nums || 0 == nums.length) { return 0; } int[] dp = new int[nums

2020-05-17 19:24:54 162

原创 【链表】奇偶链表

一、题目力扣原题:https://leetcode-cn.com/problems/odd-even-linked-list/二、额外开辟空间/** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * ListNode(int x) { val = x; } * } */class Solution { publi

2020-05-17 18:36:27 235

原创 【二叉树】中序遍历

一、题目力扣原题:https://leetcode-cn.com/problems/binary-tree-inorder-traversal/前序遍历:https://blog.csdn.net/sinat_34596644/article/details/106130854后序遍历:https://blog.csdn.net/sinat_34596644/article/details/106131335二、递归/** * Definition for a binary tree

2020-05-15 00:50:44 209

原创 【二叉树】前序遍历(先序遍历)

一、题目力扣原题:https://leetcode-cn.com/problems/binary-tree-preorder-traversal/二、递归/** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) { val = x; } * }

2020-05-15 00:06:32 305

原创 【二叉树】后序遍历

一、题目力扣原题:https://leetcode-cn.com/problems/binary-tree-postorder-traversal/前序遍历:https://blog.csdn.net/sinat_34596644/article/details/106130854二、递归/** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode l

2020-05-15 00:06:23 243

原创 【数组】搜索旋转排序数组(含重复元素)

一、题目力扣原题:https://leetcode-cn.com/problems/search-in-rotated-sorted-array-ii/搜索旋转排序数组(不含重复元素):https://blog.csdn.net/sinat_34596644/article/details/106118330二、二分查找class Solution { public boolean search(int[] nums, int target) { int left

2020-05-14 20:09:00 223

原创 【数组】搜索旋转排序数组

一、题目力扣原题:https://leetcode-cn.com/problems/search-in-rotated-sorted-array/二、暴力时间复杂度:O(n) 空间复杂度:O(1)三、二分查找class Solution { public int search(int[] nums, int target) { int left = 0; int right = nums.length - 1; while (le

2020-05-14 13:57:24 121

原创 【矩阵】搜索二维矩阵

一、题目力扣原题:https://leetcode-cn.com/problems/search-a-2d-matrix-ii/二、暴力class Solution { public boolean searchMatrix(int[][] matrix, int target) { if (null == matrix || 0 == matrix.length || 0 == matrix[0].length) { return false;

2020-05-14 12:17:26 301

原创 【二叉树】二叉树的右视图

一、题目力扣原题:https://leetcode-cn.com/problems/binary-tree-right-side-view/二、BFS搜索/** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) { val = x; } * }

2020-05-14 10:57:54 1211

原创 【字符串】翻转字符串里的单词

一、题目力扣原题:https://leetcode-cn.com/problems/reverse-words-in-a-string/二、APIclass Solution { public String reverseWords(String s) { if (null == s) { return s; } s = s.trim(); if (0 == s.length()) {

2020-05-14 09:48:58 151

原创 【二叉树】蛇形遍历

一、题目力扣原题:https://leetcode-cn.com/problems/binary-tree-zigzag-level-order-traversal/二、BFS搜索/** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) { val

2020-05-14 09:10:28 2194

原创 【经典】接雨水

一、题目力扣原题:https://leetcode-cn.com/problems/trapping-rain-water/submissions/二、暴力class Solution { public int trap(int[] height) { if (null == height || 0 == height.length) { return 0; } int result = 0; f

2020-05-14 09:08:21 214

原创 【链表】链表求和

一、题目力扣原题:https://leetcode-cn.com/problems/sum-lists-lcci/submissions/二、双指针模拟/** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * ListNode(int x) { val = x; } * } */class Solution {

2020-05-14 07:04:36 448

原创 【二叉树】路径总和(含路径)

一、题目力扣原题:https://leetcode-cn.com/problems/path-sum-ii/【二叉树】路径总和:https://blog.csdn.net/sinat_34596644/article/details/106109952二、DFS+回溯/** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; *

2020-05-14 06:43:06 538

原创 【二叉树】路径总和

一、题目力扣原题:https://leetcode-cn.com/problems/path-sum/二、递归/** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) { val = x; } * } */class Solution {

2020-05-14 00:03:50 317

原创 【模拟】螺旋矩阵

一、题目力扣原题:https://leetcode-cn.com/problems/spiral-matrix-ii/二、模拟法class Solution { public int[][] generateMatrix(int n) { // 初始化二维矩阵 int[][] result = new int[n][n]; for (int i = 0; i < n; i++) { for (int j =

2020-05-13 23:31:58 136

原创 【经典】跳跃游戏

一、题目力扣原题:https://leetcode-cn.com/problems/jump-game/submissions/二、深度优先搜索classSolution{privateint[]nums;privateboolean[]visited;publicbooleancanJump(int[]nums){if(null==nums||0==nums.length){r...

2020-05-12 22:54:55 257

原创 【经典】买卖股票的最佳时机(多次交易)

一、题目力扣原题:https://leetcode-cn.com/problems/best-time-to-buy-and-sell-stock-ii/二、峰谷法class Solution { public int maxProfit(int[] prices) { int result = 0; int i = 0; while (i < prices.length - 1) { // 找到下一个谷

2020-05-12 20:14:54 340

原创 【经典】买卖股票的最佳时机(单次交易)

一、题目力扣原题:https://leetcode-cn.com/problems/best-time-to-buy-and-sell-stock/二、暴力时间复杂度:O(n^2) 空间复杂度:O(1)三、一次遍历class Solution { public int maxProfit(int[] prices) { if (null == prices || 0 == prices.length) { return 0;

2020-05-12 13:20:38 171

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

一、题目力扣原题:https://leetcode-cn.com/problems/find-minimum-in-rotated-sorted-array/二、排序class Solution { public int findMin(int[] nums) { if (null == nums || 0 == nums.length) { return -1; } Arrays.sort(nums);

2020-05-11 22:04:15 216

原创 【二叉树】二叉树的重建

一、题目力扣原题《从前序与中序遍历序列构造二叉树》:https://leetcode-cn.com/problems/construct-binary-tree-from-preorder-and-inorder-traversal/力扣原题《从中序与后序遍历序列构造二叉树》:https://leetcode-cn.com/problems/construct-binary-tree-from-inorder-and-postorder-traversal/二、递归/** * Defin

2020-05-11 20:42:18 188

原创 【二叉树】二叉搜索树的最近公共祖先

一、题目力扣原题:https://leetcode-cn.com/problemset/all/?listId=ex0k24j类似题目:https://leetcode-cn.com/problems/lowest-common-ancestor-of-a-binary-tree/二叉搜索树是特殊的二叉树,因此二叉树查找“最近公共祖先”的方法同样适用于二叉搜索树,https://blog.csdn.net/sinat_34596644/article/details/106029076。本文只针

2020-05-10 22:38:43 365

原创 【链表】反转链表

一、题目力扣原题:https://leetcode-cn.com/problems/reverse-linked-list/二、辅助空间/** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * ListNode(int x) { val = x; } * } */class Solution { public L

2020-05-10 18:23:42 88

原创 【链表】旋转链表

一、题目力扣原题:https://leetcode-cn.com/problems/rotate-list/二、模拟法/***Definitionforsingly-linkedlist.*publicclassListNode{*intval;*ListNodenext;*ListNode(intx){val=x;}*}*/classSolution{publicListNoder...

2020-05-10 13:55:42 253

原创 【链表】排序链表

一、题目乐扣原题:https://leetcode-cn.com/problems/sort-list/submissions/二、转化为数组/***Definitionforsingly-linkedlist.*publicclassListNode{*intval;*ListNodenext;*ListNode(intx){val=x;}*}*/classSolution{publi...

2020-05-10 11:10:11 270

原创 【数组】最接近的三数之和

一、题目力扣原题:https://leetcode-cn.com/problems/3sum-closest/二、暴力classSolution{publicintthreeSumClosest(int[]nums,inttarget){intresult=-1;intdelta=Integer.MAX_VALUE;for(inti=0;i<nums.length;i++){...

2020-05-10 09:49:19 264

原创 【二叉树】二叉树的最近公共祖先

一、题目力扣原题:https://leetcode-cn.com/problems/lowest-common-ancestor-of-a-binary-tree/二、递归/** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) { val = x;

2020-05-09 23:41:45 472

原创 【二叉树】验证二叉搜索树

一、题目二叉树定义:节点的左子树只包含小于当前节点的数。 节点的右子树只包含大于当前节点的数。 所有左子树和右子树自身必须也是二叉搜索树。力扣原题:https://leetcode-cn.com/problems/validate-binary-search-tree/二、递归/** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left

2020-05-08 23:32:05 143

空空如也

空空如也

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

TA关注的人

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