自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(169)
  • 资源 (1)
  • 收藏
  • 关注

原创 LeetCode剑指offer26 树的子结构(JAVA)

class Solution { public boolean isSubStructure(TreeNode A, TreeNode B) { if(A == null || B == null) return false; return help(A, B) || isSubStructure(A.left, B) || isSubStructure(A.right, B); } public boolean help(.

2021-01-09 20:10:55 15

原创 LeetCode 1710卡车上的最大单元数(java)

class Solution { public int maximumUnits(int[][] boxTypes, int truckSize) { Arrays.sort(boxTypes, (a, b) ->{ return -(a[1] - b[1]); }); int res = 0; for(int i = 0; i< boxTypes.length; ++i) { .

2021-01-04 13:12:05 28

原创 LeetCode 1704判断字符串的两半是否相似(java)

class Solution { public boolean halvesAreAlike(String s) { // 先将字符串转化为小写,再转化为字符数组 char[] ch = s.toLowerCase().toCharArray(); int count1 = 0, count2 = 0, len = ch.length >> 1; for(int i = 0; i< ch.length; i++) { .

2021-01-04 12:59:47 26

原创 LeetCode 1688比赛中的配对次数(java)

class Solution { public int numberOfMatches(int n) { return n == 1 ? 0 : n - 1; }}

2021-01-03 22:27:40 16

原创 LeetCode 1700无法吃午餐的学生数量(java))

class Solution { public int countStudents(int[] students, int[] sandwiches) { int [] amount = new int[2]; for(int i : students) amount[i]++; for(int i : sandwiches) { if(amount[i] > 0) .

2021-01-03 22:19:52 36 1

原创 LeetCode 1672最富有客户的资产总量(java)

class Solution { public int maximumWealth(int[][] accounts) { int max = 0; for(int i =0; i< accounts.length; i++) { int x = 0; for(int j = 0; j < accounts[i].length; j++) { x += accounts[i].

2021-01-02 20:40:17 39

原创 LeetCode 164最大间距(java)

class Solution { public int maximumGap(int[] nums) { int len = nums.length; Arrays.sort(nums); int temp = 0; int res = 0; if(len < 2) return 0; for(int i = 0; i < len - 1; i++) { .

2020-11-26 09:15:45 20

原创 LeetCode 324摆动排序(java)

class Solution { public void wiggleSort(int[] nums) { Arrays.sort(nums); int len = nums.length; // 数组克隆,再排序 int[] temp = nums.clone(); for(int i = 0; i < len/ 2; i++) { nums[2 * i] = temp[(len - 1).

2020-11-18 08:35:08 20

原创 LeetCode 1329按矩阵对角线排序(java)

class Solution { public int[][] diagonalSort(int[][] mat) { int m = mat.length, n = mat[0].length; for(int k = 0; k < Math.min(m, n); k++) { for(int i = 0; i< m - 1; i++) { for(int j = 0; j < n -.

2020-11-18 08:22:06 86

原创 LeetCode 1414和为k的最小斐波切纳数字数目(java)

class Solution { public int findMinFibonacciNumbers(int k) { if(k == 0) return 0; int a = 1, b = 1; while(b <= k) { b += a; a = b -a; } return findMinFibonacciNumbers(k - .

2020-11-15 22:22:09 17

原创 LeetCode 738单调递增的数字(java)

class Solution { public int monotoneIncreasingDigits(int N) { int i = 1; int res = N; while( i <= res/10) { int temp = res / i % 100; i *= 10; if(temp / 10 > temp % 10) .

2020-11-01 10:58:27 27

原创 LeetCode 1374生成每种字符都是奇数个的字符串(java)

class Solution { public String generateTheString(int n) { if(n < 1) return ""; char[] ch = new char[n]; for(int i = 0; i < n- 1; i++) { ch[i] = 'a'; } ch[n - 1] = (n & 1) == .

2020-10-21 14:07:15 21

原创 LeetCode 1389按既定顺序创建目标数组(java)

class Solution { public int[] createTargetArray(int[] nums, int[] index) { List<Integer> list = new ArrayList<>(); for(int i = 0; i < index.length; i++) { list.add(index[i], nums[i]); }..

2020-10-21 13:51:28 23 1

原创 LeetCode 1464数组中两元素的最大乘积(java)

class Solution { public int maxProduct(int[] nums) { int temp1 = nums[0], temp2 = nums[1]; for(int i = 2; i< nums.length; i ++) { if(temp1 > temp2) temp2 = nums[i] > temp2 ? nums[i] : temp2; .

2020-10-21 13:41:53 16

原创 LeetCode 1523在区间范围内统计奇数数目(java)

```javaclass Solution { public int countOdds(int low, int high) { return (high + 1) / 2 - low / 2; }}

2020-10-20 13:34:57 22

原创 LeetCode 1460通过翻转子数组使两个数组相等(java)

class Solution { public boolean canBeEqual(int[] target, int[] arr) { Arrays.sort(target); Arrays.sort(arr); for(int i = 0; i < arr.length; i++) { if(arr[i] != target[i]) return false; }..

2020-10-20 13:27:55 18

原创 LeetCode 1323 6和9组成的最大数字(java)

class Solution { public int maximum69Number (int num) { int pos = 0, temp = num, n =1; while(temp != 0) { pos = temp % 10 == 6 ? n : pos; temp = temp / 10; n ++; } return pos == 0 ? .

2020-10-20 13:22:28 14

原创 LeetCode 1512好数对的数目(java)

class Solution { public int numIdenticalPairs(int[] nums) { int res =0, len = nums.length; if(len > 1) { for(int i = 0; i < len; i++) { for(int j = i + 1; j < len; j++){ .

2020-10-19 13:44:29 28

原创 LeetCode 1624两个相同字符之间的最长子字符串(java)

class Solution { public int maxLengthBetweenEqualCharacters(String s) { int size = s.length(); int res = -1; for(int start = 0; start < size - 1; start++) { for(int end = start + 1; end < size; end++) { .

2020-10-19 13:38:28 31

原创 LeetCode1619删除某些元素后的数组均值(java)

class Solution { public double trimMean(int[] arr) { Arrays.sort(arr); int len = arr.length; int start = len / 20, end = len - len / 20; double sum = 0; for(int i = start;i < end; i++) { sum += a..

2020-10-19 13:30:59 26

原创 LeetCode 1385两个数组间的距离值(java)

class Solution { public int findTheDistanceValue(int[] arr1, int[] arr2, int d) { int res = 0; for(int i = 0; i < arr1.length; i++) { boolean flag = false; for(int j = 0; j < arr2.length; j++) { ..

2020-10-16 08:27:27 16

原创 Leetcode 1455检查单词是否为句中其他单词的前缀(java)

class Solution { public int isPrefixOfWord(String sentence, String searchWord) { if(null == sentence || null == searchWord) return -1; String [] str = sentence.split(" "); for(int i = 0; i < str.length; ++i) {..

2020-10-14 21:06:53 17

原创 LeetCode 1450在给定时间做作业的学生人数(java)

class Solution { public int busyStudent(int[] startTime, int[] endTime, int queryTime) { int res = 0; for(int i = 0; i< startTime.length; i++) { if(queryTime >= startTime[i] && queryTime <= endTime[i]) ..

2020-10-14 20:55:06 13

原创 LeetCode 1446 连续字符(java)

class Solution { public int maxPower(String s) { int len = s.length(); if(len <= 1) return len; int res = 1; char[] chS = s.toCharArray(); for(int i = 0; i < len - 1; ++i) { int j..

2020-10-14 20:47:32 14

原创 LeetCode 1266访问所有点的最小时间(java)

class Solution { public int minTimeToVisitAllPoints(int[][] points) { int res = 0; for(int i = 1; i< points.length; ++i) { res += Math.max(Math.abs(points[i][0] - points[i -1][0]), Math.abs(points[i][1] - points[i - 1][..

2020-10-12 14:03:52 26

原创 LeetCode 1281整数的各位积和之差(java)

class Solution { public int subtractProductAndSum(int n) { int temp = 1; int sum = 0; while(n != 0) { temp *= n %10; sum += n % 10; n /= 10; } return temp - sum; }}

2020-10-12 13:58:52 21

原创 LeetCode 946验证栈序列(java)

class Solution { public boolean validateStackSequences(int[] pushed, int[] popped) { if(null == pushed || null == popped) return false; Stack<Integer> stack = new Stack<>(); int pos = 0; for(int.

2020-10-10 08:56:57 26

原创 LeetCode 142环形链表2(java)

public class Solution { public ListNode detectCycle(ListNode head) { if(null == head) return null; ListNode fast = head, slow = head; while (true) { if (fast == null || fast.next == null) return null;.

2020-10-10 08:25:23 17

原创 LeetCode 1232缀点成线(java)

class Solution { public boolean checkStraightLine(int[][] coordinates) { if( coordinates.length == 2) return true; for(int i = 0; i< coordinates.length - 2; ++i) { int x1 = coordinates[i + 1][0] - coordina..

2020-10-09 10:41:48 19

原创 LeetCode 1299将每个元素替换为右侧最大元素(java)

class Solution { public int[] replaceElements(int[] arr) { int max = -1; int len = arr.length; for(int i = len - 1; i >= 0; i--) { int temp = arr[i]; arr[i] = max; max = Math.max(max, temp.

2020-10-09 10:24:28 40

原创 LeetCode 1413逐步求和得到整数的最小值(java)

class Solution { public int minStartValue(int[] nums) { int sum = 0, start = 0; for(int num : nums) { sum += num; start = Math.max(start, 1 - sum); } return Math.max(start, 1); }}

2020-10-05 11:50:02 20

原创 LeetCode 1408数组中的字符串匹配(java)

class Solution { public List<String> stringMatching(String[] words) { List<String> res = new ArrayList<>(); if(null == words) return res; String str = String.join("-",words); for(String w.

2020-10-05 11:45:02 19

原创 LeetCode1539第k个缺失的正整数(java)

class Solution { public int findKthPositive(int[] arr, int k) { int len = arr.length; if(null == arr) { return 0; } for(int i = 0; i < len; i++) { if(arr[i] - i - 1 >= k) r.

2020-10-03 09:20:15 27

原创 LeetCode 1528重新排列字符串(java)

class Solution { public String restoreString(String s, int[] indices) { if(null == s || null == indices) return null; char [] ch = new char[indices.length]; for(int i = 0; i < indices.length; i++) { ..

2020-10-03 08:55:59 29

原创 LeetCode 1550存在连续三个奇数的数组(java)

class Solution { public boolean threeConsecutiveOdds(int[] arr) { if(null == arr) return false; int count = 0; for(int temp : arr) { if(temp %2 != 0 ) count++; else .

2020-10-02 10:44:22 38

原创 LeetCode 771宝石与石头(Java)

class Solution { public int numJewelsInStones(String J, String S) { if(J == null || S== null ) return 0; int num = 0; for(char s : S.toCharArray()) { for(char j : J.toCharArray()) { if(s.

2020-10-02 10:39:08 24

原创 LeetCode 1013 将数组分成和相等的三个部分(java)

class Solution { public boolean canThreePartsEqualSum(int[] A) { if(null == A) return false; int sum = 0; for(int a : A) { sum += a; } if(sum %3 != 0) return false; .

2020-09-28 14:02:07 14

原创 LeetCode 1010总持续时间可被60整除的歌曲(java)

class Solution { public int numPairsDivisibleBy60(int[] time) { int [] dp = new int[60]; int res = 0; for(int t : time) { int m = t % 60; int n = (60 - m) % 60; res += dp[n]; dp[m.

2020-09-28 13:48:58 26

原创 LeetCode 883三维形体投影面积(JAVA)

class Solution { public int projectionArea(int[][] grid) { int len = grid.length; int xz = 0, yz = 0, xy = 0; for(int i = 0; i < len; ++i) { int temp = 0; for(int j = 0; j< grid[i].length; ++j) {..

2020-09-28 11:25:37 21

原创 LeetCode 495提莫攻击(JAVA)

class Solution { public int findPoisonedDuration(int[] timeSeries, int duration) { int len = timeSeries.length; if(len == 0) return 0; int res = 0; for(int i = 0; i < len - 1; ++i) { if(timeS.

2020-09-27 00:30:01 17

java面试宝典

《Java面试宝典》着力于java程序员可能会被面试官问道题目,并对求职中签约、毁约的注意事项及群体面试进行了解析。《Java面试宝典》的面试题除了有详细的解析外,对相关知识点也有扩展说明。希望这些内容对读者从求职就业到提升计算机专业知识有显著的帮助。   《Java面试宝典)》适合(但不限于)将要找工作的程序员、高校计算机类应届毕业生,以及其他计算机爱好者阅读。

2019-03-27

空空如也

空空如也

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

TA关注的人 TA的粉丝

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