- 博客(271)
- 收藏
- 关注
原创 JAVA中级之多线程
多线程即在同一时间,可以做多件事情。创建多线程有3种方式,分别是继承线程类,实现Runnable接口,匿名类线程概念首先要理解进程(Processor)和线程(Thread)的区别进程:启动一个LOL.exe就叫一个进程。 接着又启动一个DOTA.exe,这叫两个进程。线程:线程是在进程内部同时做的事情,比如在LOL里,有很多事情要同时做,比如"盖伦” 击杀“提莫”,同时“赏金猎人”...
2020-07-16 18:56:54
318
1
原创 JAVA中级之多线程
多线程即在同一时间,可以做多件事情。创建多线程有3种方式,分别是继承线程类,实现Runnable接口,匿名类线程概念首先要理解进程(Processor)和线程(Thread)的区别进程:启动一个LOL.exe就叫一个进程。 接着又启动一个DOTA.exe,这叫两个进程。线程:线程是在进程内部同时做的事情,比如在LOL里,有很多事情要同时做,比如"盖伦” 击杀“提莫”,同时“赏金猎人”...
2020-07-16 18:56:41
277
原创 LeetCode33:搜索旋转排序数组
class Solution { public int search(int[] nums, int target) { if(nums.length == 0){ return -1; } int left = 0; int right = nums.length - 1; while(left <=right){ int mid = left + (righ...
2020-07-16 18:56:30
273
原创 LeetCode35:搜索插入位置
class Solution { public int searchInsert(int[] nums, int target) { int left = 0, right = nums.length - 1; // 注意 while(left <= right) { // 注意 int mid = (left + right) / 2; // 注意 if(nums[mid] == target) { // ...
2020-07-16 18:56:21
204
原创 LeetCode39:组合总和
class Solution { public List<List<Integer>> combinationSum(int[] candidates, int target) { //创建结果数组 List<List<Integer>> ans = new ArrayList<>(); //调用回溯方法 backtrack(0,candidates,target,ne...
2020-07-16 18:56:12
99
原创 LeetCode40:组合总和 ||
class Solution { public List<List<Integer>> combinationSum2(int[] candidates, int target) { //创建结果数组 List<List<Integer>> ans = new ArrayList<>(); if(candidates.length == 0 || target...
2020-07-16 18:55:58
114
原创 LeetCode46:全排列
class Solution { public List<List<Integer>> permute(int[] nums) { //创建结果数组 List<List<Integer>> ans = new ArrayList<>(); //回溯 backtrack(nums,new ArrayList<Integer>(),ans); re...
2020-07-16 18:55:46
121
原创 LeetCode47:全排列 ||
class Solution { public List<List<Integer>> permuteUnique(int[] nums) { //创建一个结果数组 List<List<Integer>> ans = new ArrayList<>(); if(nums.length == 0){ return ans; } ...
2020-07-16 18:55:36
99
原创 LeetCode53:最大子序和
class Solution { public int maxSubArray(int[] nums) { int ans = nums[0]; int sum = 0; for(int num :nums){ if(sum > 0){ sum += num; } else{ sum = num; ...
2020-07-16 18:55:23
116
原创 LeetCode56:合并区间
class Solution { public int[][] merge(int[][] intervals) { //1.按照区间的起始位置排序 Arrays.sort(intervals,(v1,v2)->v1[0]-v2[0]); //2.创建一个结果数组 int[][] res = new int[intervals.length][2]; int idx = -1; for(int...
2020-07-16 18:55:12
195
原创 LeetCode57:插入区间
class Solution { public int[][] insert(int[][] intervals, int[] newInterval) { List<int[]> res = new ArrayList<>(); int i = 0; while (i < intervals.length && newInterval[0] > intervals[i][1]) { ...
2020-07-15 17:04:06
132
原创 LeetCode61:旋转链表
/** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * ListNode(int x) { val = x; } * } */class Solution { public ListNode rotateRight(ListNode head, int k) { // base cases if (head...
2020-07-15 17:03:56
144
原创 LeetCode62:不同路径
class Solution { public int uniquePaths(int m, int n) { int[][] dp = new int[m+1][n+1]; //base for(int i = 1;i <=n;i++ ){ dp[1][i] = 1; } for(int i = 1;i <= m;i++){ dp[i][1] = 1;...
2020-07-15 17:03:45
104
原创 LeetCode63:不同路径||
class Solution { public int uniquePathsWithObstacles(int[][] obstacleGrid) { int R = obstacleGrid.length; int C = obstacleGrid[0].length; // If the starting cell has an obstacle, then simply return as there would be ...
2020-07-15 17:03:35
104
原创 LeetCode64:最小路径和
class Solution { public int minPathSum(int[][] grid) { int r = grid.length; int c = grid[0].length; int[][] dp = new int[r][c]; //base dp[0][0] = grid[0][0]; for(int i =1;i<c;i++){ dp[0...
2020-07-15 17:03:27
122
原创 LeetCode72:编辑距离
class Solution { public int minDistance(String word1, String word2) { int m = word1.length(); int n = word2.length(); int[][] dp = new int[m+1][n+1]; //base for(int i = 1;i <= m;i++){ dp[i][0] ...
2020-07-15 17:03:18
133
原创 LeetCode76:最小覆盖字串
class Solution { public String minWindow(String s, String t) { if(t.length()> s.length()) return ""; HashMap<Character, Integer> map = new HashMap<>(); for(char c: t.toCharArray()) map.put(c, map.getOrDefau...
2020-07-15 17:02:58
162
原创 LeetCode78:子集
class Solution { public List<List<Integer>> subsets(int[] nums) { //创建结果数组 List<List<Integer>> ans = new ArrayList<>(); //回溯 backtrack(0,nums,new ArrayList<Integer>() ...
2020-07-15 17:02:48
105
原创 LeetCode81:搜索旋转排序数组||
class Solution { public boolean search(int[] nums, int target) { if(nums.length == 0){ return false; } int left = 0; int right = nums.length - 1; while(left <= right){ int mid = lef...
2020-07-15 17:02:38
98
原创 LeetCode83:删除排序链表中的重复元素
/** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * ListNode(int x) { val = x; } * } */class Solution { public ListNode deleteDuplicates(ListNode head) { ListNode cur = head; ...
2020-07-15 17:02:29
100
原创 LeetCode88:合并两个有序数组
class Solution { public void merge(int[] nums1, int m, int[] nums2, int n) {/** int p1 = m - 1; int p2 = n - 1; int p = m + n - 1; while ((p1 >= 0) && (p2 >= 0)) nums1[p--] = (nums1[p1] < nu...
2020-07-14 08:06:05
87
原创 LeetCode90:子集||
class Solution { public List<List<Integer>> subsetsWithDup(int[] nums) { //创建结果数组 List<List<Integer>> ans = new ArrayList<>(); //不重复问题一般先排序 Arrays.sort(nums); //调用回溯 back...
2020-07-14 08:05:54
108
原创 LeetCode102:二叉树的层序遍历
/** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) { val = x; } * } */class Solution { public List<List<Integer>> levelOrder(TreeNod...
2020-07-14 08:05:44
76
原创 LeetCode103:二叉树的锯齿形层次遍历
/** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) { val = x; } * } */class Solution { public List<List<Integer>> zigzagLevelOrder(T...
2020-07-14 08:05:34
77
原创 LeetCode104:二叉树的最大深度
/** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) { val = x; } * } */class Solution { public int maxDepth(TreeNode root) { //层数就是深度 ...
2020-07-14 08:05:22
109
原创 LeetCode107:二叉树的层次遍历||
/** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) { val = x; } * } */class Solution { public List<List<Integer>> levelOrderBottom(T...
2020-07-14 08:05:06
67
原创 LeetCode111:二叉树的最小深度
/** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) { val = x; } * } */class Solution { public int minDepth(TreeNode root) { LinkedList&l...
2020-07-14 08:04:56
76
原创 LeetCode112:路径总和
/** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) { val = x; } * } */class Solution { public boolean hasPathSum(TreeNode root, int sum) { ...
2020-07-14 08:04:43
142
原创 LeetCode113:路径总和||
/** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) { val = x; } * } */class Solution { public List<List<Integer>> pathSum(TreeNode ...
2020-07-14 08:04:31
94
原创 LeetCode141:环形链表
/** * Definition for singly-linked list. * class ListNode { * int val; * ListNode next; * ListNode(int x) { * val = x; * next = null; * } * } */public class Solution { public boolean hasCycle(ListNode head)...
2020-07-14 08:04:19
58
原创 LeetCode142:环形链表||
/** * Definition for singly-linked list. * class ListNode { * int val; * ListNode next; * ListNode(int x) { * val = x; * next = null; * } * } */public class Solution { public ListNode detectCycle(ListNode h...
2020-07-13 20:03:19
74
原创 LeetCode153:寻找旋转排序数组中的最小值
class Solution { public int findMin(int[] nums) { int left = 0; int right = nums.length - 1; while (left < right) { int mid = left + (right - left) / 2; if (nums[mid] > nums[right]) { ...
2020-07-13 20:03:08
64
原创 LeetCode154:寻找旋转排序数组中的最小值||
class Solution { public int findMin(int[] nums) { int left = 0; int right = nums.length - 1; while (left <= right) { int mid = (left + right) / 2; if (nums[mid] > nums[right]) left = mid + 1; ...
2020-07-13 20:02:58
91
原创 LeetCode160:相交链表
/** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * ListNode(int x) { * val = x; * next = null; * } * } */public class Solution { public ListNode getIntersection...
2020-07-13 20:02:47
71
原创 LeetCode198:打家劫舍
class Solution { public int rob(int[] nums) { if(nums.length==0){ return 0; } int[] dp = new int[nums.length+1]; //base dp[0] = 0; dp[1] = nums[0]; //状态转移 for(int i =2;i<...
2020-07-13 20:02:38
131
原创 LeetCode206:反转链表
/** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * ListNode(int x) { val = x; } * } */class Solution { public ListNode reverseList(ListNode head) { ListNode pre = null; ...
2020-07-13 20:02:29
63
原创 LeetCode207:课程表
class Solution { public boolean canFinish(int numCourses, int[][] prerequisites) { //入度表 int[] indegrees = new int[numCourses]; //课程安排图的 邻接表 List<List<Integer>> adjacency = new ArrayList<>...
2020-07-13 20:02:18
125
原创 LeetCode209:长度最小的子数组
class Solution { public int minSubArrayLen(int s, int[] nums) { int n = nums.length; if(n == 0){ return 0; } int left = 0,right = 0; int min = Integer.MAX_VALUE; int sum = 0; while(...
2020-07-13 20:02:07
118
原创 LeetCode210:课程表||
class Solution { public int[] findOrder(int numCourses, int[][] prerequisites) { if (numCourses <= 0) { return new int[0]; } //入度表 HashSet<Integer>[] adj = new HashSet[numCourses]; for (in...
2020-07-13 20:01:55
180
原创 LeetCode213:打家劫舍||
class Solution { public int rob(int[] nums) { if(nums.length == 0) return 0; if(nums.length == 1) return nums[0]; int[] nums1 = Arrays.copyOfRange(nums, 1, nums.length); int[] nums2 = Arrays.copyOfRange(nums, 0, nums....
2020-07-13 20:01:43
195
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人