自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

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

原创 leetcode 383. Ransom Note

class Solution { public boolean canConstruct(String ransomNote, String magazine) { //记录杂志字符串出现的次数 int[] arr = new int[26]; int temp; for (int i = 0; i < magazine.length(); i++) { temp = magazine.charAt(i).

2021-08-14 17:59:17 120

原创 leetcode 121. Best Time to Buy and Sell Stock

121. Best Time to Buy and Sell Stockclass Solution { public int maxProfit(int[] prices) { /* 考虑每次如何获取最大收益? 第i天的最大收益只需要知道前i天的最低点就可以算出来了。 而第i天以前(包括第i天)的最低点和i-1天的最低点有关: dp[i] = min(d[i-1],prices[i]) 其中dp[0

2021-08-14 16:09:32 109

原创 leetcode 130. Surrounded Regions

leetcode 130. Surrounded Regionsclass Solution { public void solve(char[][] board) { //[row][col] int rows=board.length; int columns=board[0].length; for (int i=0;i<rows;i++) { if (board[i][0]=='O') bou

2021-08-11 16:14:18 85

原创 leetcode 1222. Queens That Can Attack the King

we will start from the king position and check in each of the 8 directions (row 2, col 2, diagonal 2), if there is a queen in the line. Once we’ve found a queen in this direction, we break, cuz it will potentially block the way of other queens in the s...

2021-08-11 15:13:58 92

原创 leetcode 846. Hand of Straights

class Solution { public boolean isNStraightHand(int[] hand, int W) { PriorityQueue<Integer> minHeap = new PriorityQueue<>(); for(int i : hand){ minHeap.add(i); } while(minHeap.size() != 0) { .

2021-08-11 14:57:49 73

原创 leetcode 128. Longest Consecutive Sequence

leetcode 128. Longest Consecutive Sequenceclass Solution { public int longestConsecutive(int[] nums) { Set<Integer> set = new HashSet<Integer>(); for (int num: nums){ set.add(num); } int max_len

2021-08-11 14:50:28 57

原创 leetcode 1910. Remove All Occurrences of a Substring

1910. Remove All Occurrences of a Substringclass Solution { public String removeOccurrences(String s, String part) { StringBuilder sb = new StringBuilder(); for (int i = 0; i<s.length(); i++){ sb.append(s.charAt(i));

2021-08-11 11:58:22 124

原创 leetcode 515. Find Largest Value in Each Tree Row

leetcode 515. Find Largest Value in Each Tree Row/** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode() {} * TreeNode(int val) { this.val = val; } * Tr

2021-08-11 09:40:57 72

原创 leetcode 16. 3Sum Closest

leetcode 16. 3Sum Closestclass Solution { public int threeSumClosest(int[] nums, int target) { int result=nums[0]+nums[1]+nums[nums.length-1]; Arrays.sort(nums); int i=0; for (i=0; i<nums.length-2; i++){

2021-08-11 08:50:42 87

原创 leetcode 1903. Largest Odd Number in String

leetcode 1903. Largest Odd Number in Stringgreedy algorithmstarting from the end, look for the last digit which is the odd number, then return from the start to that digit, would be the largest odd number.class Solution { public String largestOddNu

2021-08-10 16:47:55 137

原创 leetcode 1005. Maximize Sum Of Array After K Negations

leetcode 1005. Maximize Sum Of Array After K Negationsclass Solution { public int largestSumAfterKNegations(int[] nums, int k) { PriorityQueue<Integer> heap = new PriorityQueue(); for (int num: nums){ heap.offer(num);

2021-08-10 16:23:21 95

原创 leetcode 1046. Last Stone Weight

leetcode 1046. Last Stone Weightclass Solution { public int lastStoneWeight(int[] stones) { PriorityQueue<Integer> maxHeap = new PriorityQueue<Integer>((a, b)-> b - a); for (int num: stones){ maxHeap.offer(

2021-08-10 12:30:28 66

原创 MergeSort Algorithm

MergeSortSRC: https://www.youtube.com/watch?v=6kQWyON6iBk&list=PLK0ZC7fyo01J-PAbYSTyiZCQXH2RSNOW_&index=3// "static void main" must be defined in a public class.public class MergeSort { public static int[] mergeSort(int[] array){ int

2021-08-10 12:17:41 166

原创 leetcode 169. Majority Element

leetcode 169. Majority ElementBoyer-Moore majority vote algorithmBy definition, the majority element has to appear more than half of times, so there can only be one majority element. Using the Boyer-Moore majority vote algorithm, we keep count of the ti

2021-08-10 11:22:32 97

原创 Leetcode 23. Merge k Sorted Lists

Leetcode 23. Merge k Sorted ListsYou are given an array of k linked-lists lists, each linked-list is sorted in ascending order.Merge all the linked-lists into one sorted linked-list and return it.链接:https://leetcode-cn.com/problems/merge-k-sorted-lists

2021-08-10 11:00:40 70

空空如也

空空如也

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

TA关注的人

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