- 博客(66)
- 收藏
- 关注
原创 【经典】盛最多水的容器
一、题目力扣原题: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
331
原创 【链表】链表排序
一、题目力扣原题: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
606
原创 【经典】实现一个阻塞队列
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
328
原创 【多线程】连续打印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
246
原创 【排序】归并排序
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
148
原创 【多线程】双线程交替打印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
2492
原创 【排序】快速排序
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
275
原创 【动态规划】最长上升子序列
一、题目力扣原题: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
180
原创 【链表】奇偶链表
一、题目力扣原题: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
252
原创 【二叉树】中序遍历
一、题目力扣原题:https://leetcode-cn.com/problems/binary-tree-inorder-traversal/前序遍历:https://blog.youkuaiyun.com/sinat_34596644/article/details/106130854后序遍历:https://blog.youkuaiyun.com/sinat_34596644/article/details/106131335二、递归/** * Definition for a binary tree
2020-05-15 00:50:44
232
原创 【二叉树】前序遍历(先序遍历)
一、题目力扣原题: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
328
原创 【二叉树】后序遍历
一、题目力扣原题:https://leetcode-cn.com/problems/binary-tree-postorder-traversal/前序遍历:https://blog.youkuaiyun.com/sinat_34596644/article/details/106130854二、递归/** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode l
2020-05-15 00:06:23
272
原创 【数组】搜索旋转排序数组(含重复元素)
一、题目力扣原题:https://leetcode-cn.com/problems/search-in-rotated-sorted-array-ii/搜索旋转排序数组(不含重复元素):https://blog.youkuaiyun.com/sinat_34596644/article/details/106118330二、二分查找class Solution { public boolean search(int[] nums, int target) { int left
2020-05-14 20:09:00
248
原创 【数组】搜索旋转排序数组
一、题目力扣原题: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
144
原创 【矩阵】搜索二维矩阵
一、题目力扣原题: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
329
原创 【二叉树】二叉树的右视图
一、题目力扣原题: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
1246
原创 【字符串】翻转字符串里的单词
一、题目力扣原题: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
172
原创 【二叉树】蛇形遍历
一、题目力扣原题: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
2305
原创 【经典】接雨水
一、题目力扣原题: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
235
原创 【链表】链表求和
一、题目力扣原题: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
475
原创 【二叉树】路径总和(含路径)
一、题目力扣原题:https://leetcode-cn.com/problems/path-sum-ii/【二叉树】路径总和:https://blog.youkuaiyun.com/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
576
原创 【二叉树】路径总和
一、题目力扣原题: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
344
原创 【模拟】螺旋矩阵
一、题目力扣原题: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
159
原创 【经典】跳跃游戏
一、题目力扣原题: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
285
原创 【经典】买卖股票的最佳时机(多次交易)
一、题目力扣原题: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
394
原创 【经典】买卖股票的最佳时机(单次交易)
一、题目力扣原题: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
184
原创 【数组】寻找旋转排序数组中的最小值
一、题目力扣原题: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
244
原创 【二叉树】二叉树的重建
一、题目力扣原题《从前序与中序遍历序列构造二叉树》: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
202
原创 【二叉树】二叉搜索树的最近公共祖先
一、题目力扣原题:https://leetcode-cn.com/problemset/all/?listId=ex0k24j类似题目:https://leetcode-cn.com/problems/lowest-common-ancestor-of-a-binary-tree/二叉搜索树是特殊的二叉树,因此二叉树查找“最近公共祖先”的方法同样适用于二叉搜索树,https://blog.youkuaiyun.com/sinat_34596644/article/details/106029076。本文只针
2020-05-10 22:38:43
460
原创 【链表】反转链表
一、题目力扣原题: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
104
原创 【链表】旋转链表
一、题目力扣原题:https://leetcode-cn.com/problems/rotate-list/二、模拟法/***Definitionforsingly-linkedlist.*publicclassListNode{*intval;*ListNodenext;*ListNode(intx){val=x;}*}*/classSolution{publicListNoder...
2020-05-10 13:55:42
304
原创 【链表】排序链表
一、题目乐扣原题: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
332
原创 【数组】最接近的三数之和
一、题目力扣原题: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
288
原创 【二叉树】二叉树的最近公共祖先
一、题目力扣原题: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
535
原创 【二叉树】验证二叉搜索树
一、题目二叉树定义:节点的左子树只包含小于当前节点的数。 节点的右子树只包含大于当前节点的数。 所有左子树和右子树自身必须也是二叉搜索树。力扣原题: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
163
原创 HBase学习笔记 - 实践篇
前言:本篇主要是笔者在工作过程中发现或遇到的问题的一些总结。不涉及HBase基础及原理的探讨,如有需要,可参照笔者前两篇文章:基础篇、架构篇。单调递增的RowKey有何不妥?关于RowKey的设计,HBase的官方文档是给了一些案例的,建议可以通读官方文档的相应章节。单调递增的RowKey(如时间戳),可能会出现一段时间内,客户端仅访问某个RegionServer的情况,不但降低了热点数据...
2019-04-06 13:06:28
321
原创 HBase学习笔记 - 架构篇
前言:本篇主要梳理了HBase的架构设计,更多关于HBase的基础知识请参照《HBase学习笔记 - 基础篇》或HBase官方文档:http://hbase.apache.org/book.html除了官方文档,本文也引用了其他大神的观点,并结合自己的思路和理解输出到本文中。因为内容很长,写到后面,有些模块有点偷懒了,后续有机会补上。如有疑问,欢迎留言一起探讨,共同进步。...
2019-04-06 12:26:59
325
原创 HBase学习笔记 - 基础篇
前言:本篇主要梳理了HBase的基础知识,不涉及环境的搭建及原理的深入探讨,算是阶段性学习的总结。文中观点大部分源于HBase官方文档,并且为了不曲解其原意,不做多余的中文翻译。更多详情请参照HBase官方文档:http://hbase.apache.org/book.html一、什么是HBase?HBase(Hadoop Database, 以下简称HBase)是Apache Ha...
2019-03-15 00:09:58
318
原创 IoC容器的初始化流程分析
前言:本文参考了《Spring核心内幕 - 深入解析Spring架构与设计原理(第2版)》一书,结合笔者对源码的阅读得到的关于Spring IoC容器初始化流程的理解。一、什么是控制反转(IoC,Inversion of Control)? 在进入正题之前,首先我们有必要先了解一下控制反转这个概念,“反转”的是什么?为什么要进行控制反转?1.传统的对象依赖关系管理public class M...
2018-05-21 20:46:11
9853
原创 Spring静态配置加载原理剖析
一、何为静态配置应用配置大致可以分为两类:动态配置和静态配置。动态配置:常用zookeeper存储,未预定义在应用中,具体值在运动时动态获取。静态配置:预定义于应用中的*.properties文件,在Spring容器启动时解析k-v对,并注入到相应的${...}占位符中。二、核心类模型三、主要流程解析PlaceholderConfigurerSupport的实现类:PropertyPlacehol...
2018-05-12 18:11:59
578
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人