自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

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

原创 kafka WSL producer

背景windows10 和windows 10 下的WSL(windows10 sub Linux)linux在wsl中安装了 zookeeper(单节点模式) kafka 单节点模式 kafka的config/server.properties文件如下 # see kafka.server.KafkaConfig for additional details and defaults​############################# Server B

2020-12-26 17:14:37 309

原创 remove duplicates from Soted ListNode

/** * 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; } * }.

2020-09-15 20:09:15 200

原创 合并k个有序链表

/** * 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; } * }.

2020-08-31 21:41:36 245

原创 求数组中最大差值

/** * 求最大差值,要求必须是下标小的减下标大的 */public class MaxDiffer { public static void main(String[] args) { int[] nums = {7,1,5,3,6,4}; maxDiffer(nums); } public static void maxDiffer(int[] nums){ int preMax = Integer.MIN_VALUE...

2020-08-31 19:48:09 1721 1

原创 combination sum 3

import java.util.ArrayList;import java.util.List;/** * 给定一个数字x,要求使用k个数字求和可以得到x,数字从1-9中选择,不能重复。 * * 实现一个函数,在输入 x,k 时,输出所有可以求和得到x的列表 * * 例子: * * 输入:k= 3, x = 9 * * 输出: [[1,2,6], [1,3,5], [2,3,4]] */public class CombinationSum3 { public st.

2020-08-31 16:08:55 211

原创 最长公共字符串

给定两个字符串,返回两个字符串最长公共字符串package com.ncu.dp;public class MaxCommonString { public static void main(String[] args) { String a = "12ddd"; String b = "12hhh"; helper(a,b); } public static void helper(String a,String b){

2020-08-31 14:58:25 338

原创 Candy

ratings 数组中的值代表每个孩子的得分,给定如下规则每个孩子最少得到一个糖果相邻孩子之间,得分高的人得到的糖果比得分低的人得到的糖果数要多class Solution { public int candy(int[] ratings) { int[] nums = new int[ratings.length]; Arrays.fill(nums,1); for(int i=1;i<ratings.length;i++..

2020-08-29 15:20:24 117

原创 next greater element 3

给定一个数,求下一个包含所有该数字的数例如:12--->21若没有,则返回-1,如321class Solution { public int nextGreaterElement(int n) { char[] chars = String.valueOf(n).toCharArray(); int i=chars.length-1; for(;i>0;i--){ if(chars[i]>.

2020-08-29 11:40:41 122

原创 按字典序打印前N个数字

class Solution { public List<Integer> lexicalOrder(int n) { List<Integer> list = new ArrayList<>(); for(int i=1;i<10;i++){ dfs(i,n,list); } return list; } void dfs(int cur, int n.

2020-08-08 08:30:10 737

原创 ThreadPoolExecutor的阻塞队列满了,再增加新的任务后,执行顺序

如题,阻塞队列满了,但是线程池的线程数量小于maxPoolExecutor,此时增加新的任务,会立即执行新的任务,而不会从队列中取任务import java.util.concurrent.ArrayBlockingQueue;import java.util.concurrent.ThreadPoolExecutor;import java.util.concurrent.TimeUnit;public class ThreadSequence { public static vo.

2020-07-29 14:27:20 3714

原创 longest consecutive Sequence

// 用一个HashMap记录每个元素的最长子序列长度class Solution { public int longestConsecutive(int[] nums) { Map<Integer,Integer> map = new HashMap<>(); int maxLen = 0; for(int num:nums){ if(map.containsKey(num)) continue;.

2020-07-28 09:17:19 126

原创 Java数组的所有子集

import java.util.ArrayList;import java.util.List;public class Subarray { public static void main(String[] args) { int[] nums = new int[]{1,2,3,4}; List<List<Integer>> subarray = subarray(nums); for(int i=0;i<s.

2020-07-26 17:22:20 1411 1

原创 利用synchronized和volatile多线程打印ABC

public class PrintABC { // 重要,必须设置一个多个线程共享的状态变量 static volatile int status = 1; static class ThreadAA implements Runnable{ final Object lock; int flag; int nextFlag; String printStr; public ThreadAA(Obje.

2020-07-25 20:26:15 202

原创 Controller返回字符串直接访问页面路径设置

背景:访问一个controller,返回一个页面。返回值为页面的名称。不适用任何的模板引擎需要将我们的页面保存到resources/static文件夹中。将我们的application.yml文件设置spring.mvn.view.prefix/subfix...

2020-07-22 13:51:52 1065

原创 堆排序Java实现

package com.ncu.array;import java.util.Arrays;public class HeapSort { public static void main(String[] args) { int[] nums = {1,4,2,3,5,8,6,9,7}; headSort(nums); System.out.println(Arrays.toString(nums)); } public s.

2020-07-22 09:37:55 131

原创 find in mountain array

思路:首先使用二分法找到最高点然后从最高点左侧进行查找再从最高点右侧查找/** * // This is MountainArray's API interface. * // You should not implement it, or speculate about its implementation * interface MountainArray { * public int get(int index) {} * public int lengt.

2020-07-18 11:19:51 125

原创 binary tree right view

/** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode() {} * TreeNode(int val) { this.val = val; } * TreeNode(int val, TreeNode left, TreeNode right) { .

2020-07-12 14:24:59 118

原创 binary tree Zigzag level order

思路:层次遍历后将偶数层的list进行反转/** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode() {} * TreeNode(int val) { this.val = val; } * TreeNode(int val, TreeNode.

2020-07-11 17:32:58 134

原创 volid Sudoku

验证给定的一个二维数组是否为数独每一行的数字必须唯一 每一列的数字必须唯一 九宫格中的每三行,三列中数字必须唯一 遍历九宫格中每个数字 将当前数字属于哪一行表示成 行数 + 数字 将当前数字属于哪一列表示成 数字 +列数 将当前数字属于哪一个三宫格表示成 三宫格行数 + 数字 + 三宫格列数class Solution { public boolean isValidSudoku(char[][] board) { Set&...

2020-07-11 11:32:32 124

原创 Move even index location to tail

/** * 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; } * }.

2020-07-05 20:33:05 239

原创 reverse integer

class Solution { public int reverse(int x) { // boolean flag = true; // if(x<0){ // x = -x; // flag = false; // } // List<Integer> list = new ArrayList<>(); // while(x>=.

2020-07-05 10:18:11 1362

原创 remove duplicates from sorted array

移除排序数组中重复的数字class Solution { public int removeDuplicates(int[] nums) { if(nums.length <2) return nums.length; int id = 1; for(int i=1;i<nums.length;i++){ if(nums[i] != nums[i-1]) nums[id++] = nums[i];

2020-06-29 20:54:48 98

原创 Intersection of Two Arrays 2

寻找两个数组中共同重复的数字,并将他们装到一个数组中class Solution { public int[] intersect(int[] nums1, int[] nums2) { // 注释部分为最长的具有相同顺序的最长数组 // ArrayList<Integer> list = new ArrayList<>(); // for(int i=0;i<nums1.length;i++){ /

2020-06-27 13:38:30 107

原创 insert delete getRandom Set

class RandomizedSet { List<Integer> list = null; Map<Integer,Integer> map = null; Random random = new Random(); /** Initialize your data structure here. */ public RandomizedSet() { list = new ArrayList<>.

2020-06-26 20:20:03 117

原创 Pascals Triangle

class Solution { public List<List<Integer>> generate(int numRows) { List<List<Integer>> res = new ArrayList<>(); if(numRows == 0) return res; for(int i=0;i<numRows;i++){ .

2020-06-26 11:27:18 117

原创 first unique character in a string

在给定的一个字符串中,找到第一个唯一的字符,并返回它的下标class Solution { public int firstUniqChar(String s) {// if(s == null || "".equals(s)) return -1;// int res = -1;// Map<Character,Integer> map = new HashMap<>();// for(int i

2020-06-25 10:39:42 131

原创 Roman to Integer

罗马数字转数字Symbol ValueI 1V 5X 10L 50C 100D 500M 1000其中,一些特殊规则如下:Ican be placed beforeV(5) andX(10) to make 4 and 9. Xcan be placed beforeL(50) an...

2020-06-20 20:22:30 95

原创 Best time to buy and sell stock 2

低买高卖,可以多次进行,求最大的利润class Solution { public int maxProfit(int[] prices) { int profit = 0,i=0; while(i<prices.length){ while(i<prices.length-1 && prices[i+1]<=prices[i]) i++; int min = prices[.

2020-06-20 19:39:17 99

原创 convert sorted array to binary search tree

对给定的升序数组,将其转化成深度最低的二叉搜索树/** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode() {} * TreeNode(int val) { this.val = val; } * TreeNode(int val, TreeNode

2020-06-18 20:09:21 87

原创 浏览器正在解析主机时间过长

背景:前段时间安装了virtual box,所以,自然也就安装了virtual box的虚拟网卡,导致使用chrome浏览器的解析主机的时间很长,严重影响上网体验。解决办法:将安装virtual box所产生的虚拟网卡给禁用了,然后自然访问网站的速度就变快多了...

2020-06-14 17:23:22 1115 1

原创 判断字符串是否可以转成数字

字符串可能是如下几类+11-11+111.22-111.22"+100","5e2","-123","3.1416"和"-1E-16"如下则不可以转成数字12e","1a3.14","1.2.3","+-5"和"12e+4.3"public class Solution { public boolean isNumeric(char[] str) { try{ Double.parseDouble(new String(str

2020-06-14 17:02:39 958

原创 移除链表中重复的元素

其中链表为递增的例子:1->2->2->3->3->4->5->6移除重复的元素之后为1->4->5->6/* public class ListNode { int val; ListNode next = null; ListNode(int val) { this.val = val; }}*/import java.util.*;public class Soluti

2020-06-12 19:30:25 147

原创 byfn sh container linux.go349 starting container process caused no such file or directory

container_linux.go:349: starting container process caused "no such file or directory“在运行byfn.sh时,出现上述错误,让我很是郁闷。。。所以便查看byfn.sh 的脚本本文件执行的内容。最后发现是在运行这句话的时候出现了问题 # now run the end to end scriptdocker exec cli scripts/script.sh $CHANNEL_NAME $CLI_DEL.

2020-06-10 11:17:51 2919

原创 滑动窗口最大值

给定一个整数数组num,和一个滑动窗口的size,每次滑动窗口向右移动一个位置,求所有经过的这些滑动窗口的最大值import java.util.*;public class Solution { public ArrayList<Integer> maxInWindows(int [] num, int size){ ArrayList<Integer> res = new ArrayList<>(); if(size =

2020-06-06 19:40:31 187

原创 矩阵中的路径

给定一个字符串矩阵matrix,和这个矩阵的rows,cols即矩阵的行数和列数。再给定一个字符串,判断这个字符串是否在这个字符串矩阵中的路径中。public class Solution { public boolean hasPath(char[] matrix, int rows, int cols, char[] str){ int[] res = new int[matrix.length]; for(int i=0;i<rows;i++){

2020-06-06 10:45:23 141

原创 查看字节码文件

编译Test.java文件:javac Test.java之后会生成一个Test.class的文件,Test.class是一个16进制的文件。以16进制的形式打开用普通的文本编辑器打开Test.class文件显示的是乱码,如何以16进制的形式打开?方法一:下载打开16进制文件的软件,比较麻烦。方法二:使用Linux自带的vim编辑器,在git bash中也有vi Test.class,打开class文件,显示的会是乱码的情况。此时,将文件显示的内容转换成16进制显示形式::%!x

2020-06-05 12:03:04 1217

原创 机器人运动范围

给定一个阈值threshold,机器人运动的范围是当前运动的坐标点的各个 位上的数字相加小于等于 thresholdpublic class Solution { int count = 0; public int movingCount(int threshold, int rows, int cols){ int[][] nums = new int[rows][cols]; helper(nums,threshold,0,0); r

2020-06-05 11:04:25 218

原创 Java注解定义与使用

Java注解定义与使用Java注解声明public @interface AnnotationDemo{ }注解的属性属性的定义类似于定义接口的方法名称,没有实现,且返回值不能位voidpublic @interface AnnotationDemo2{ String attr1(); String attr2() default "default value"; String[] attr3();// 在使用时,没有默认值时其属性必须进行赋值}...

2020-06-04 09:24:21 160

原创 LFU Java实现

LFU:least frequency used,当缓存空间不足时,移除使用频率最少的元素思路:使用三种数据结构,一个是缓存的元素LFUNode<k,v>, HashMap<k,LFUNode>, TreeMap<Integer,List<LFUNode>>class LFUNode<k,V>{ private k key; private v value; private int count;

2020-06-03 10:44:33 1844

原创 kth smallest element in bst

寻找二叉搜索树第k小的节点的值思路:首先二叉搜索树的是所有右子树大于根节点,所有的左子树小于根节点。对二叉搜索树进行中序遍历,即从小到大将数放到栈中,当放入的第k个时,就为第k小的元素/** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode() {} * .

2020-06-02 19:50:44 94

空空如也

空空如也

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

TA关注的人

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