[LeetCode] 452. Minimum Number of Arrows to Burst Balloons

452. Minimum Number of Arrows to Burst Balloons Hardness: \(\color{orange}\textsf{Medium}\) Ralated Topics: Array,Greedy,Sorting 一、題目 There are some spherical balloons taped onto a flat wall that represents the XY-plane. The balloons are represented as a 2D integer array points where points[i] = [x_start, x_end] denotes a balloon whose horizontal diameter stretches between x_start and x_end. You do not know the exact y-coordinates of the balloons. Arrows can be shot up directly vertically (in the positive y-direction) from different points along the x-axis. A balloon with x_start and x_end is burst by an arrow shot at x if x_start <= x <= x_end. There is no limit to the number of arrows that can be shot. A shot arrow keeps traveling up infinitely, bursting any balloons in its path. Given the array points, return the minimum number of arrows that must be shot to burst all balloons. ...

January 5, 2023 · 2 分鐘 · Rain Hu

[LeetCode] 944. Delete Columns to Make Sorted

944. Delete Columns to Make Sorted Hardness: \(\color{green}\textsf{Easy}\) Ralated Topics: Array、String 一、題目 You are given an array of n string strs, all of the same length. The string s can be arranged such that there is one on each line, making a grid. For example, strs = ["abc", "bce", "cae" can be arranged as : abc bce cae You want to delete the columns that are not sorted lexicographically. In the aove example (0-indexed), columns 0('a','b','c') and 2('c','e','e') are sorted while column 1('b','c','a') is not, so you would delete column 1. Return the number of columns that you will delete. ...

January 3, 2023 · 2 分鐘 · Rain Hu

[LeetCode] 2522. Partition String Into Substrings With Values at Most K

2522. Partition String Into Substrings With Values at Most K Hardness: \(\color{orange}\textsf{Medium}\) Ralated Topics: \(\color{blue}\textsf{Weekly Contest 323}\) 一、題目 You are given a string s consisting of digits from 1 to 9 and an integer k. A partition of a string s is called good if: Each digit of s is part of exactly one substring. The value of each substring is less than or equal to k. Return the minimum number of substrings in a good partition of s. If no good partition of s exists, return -1. Note that: The value of a string is its result when interpreted as an integer. For example, the value of "123" is 123 and the value of "1" is 1. A substring is a contiguous sequence of characters within a string. Example 1: ...

January 2, 2023 · 2 分鐘 · Rain Hu

[LeetCode] 2523. Closest Prime Numbers in Range

2523. Closest Prime Numbers in Range Hardness: \(\color{orange}\textsf{Medium}\) Ralated Topics: \(\color{blue}\textsf{Weekly Contest 323}\) 一、題目 Given two positive integers left and right, find the two integers num1 and num2 such that: left <= nums1 < nums2 <= right. nums1 and nums2 are both prime numbers. nums2 - nums1 is the minimum amongst all other pairs satisfying the above conditions. Return the positive integer array ans = [nums1, nums2]. If there are multiple pairs satisfying these conditions, return the one with the minimum nums1 value or [-1, -1] if such numbers do not exist. A number greater than 1 is called prime if it is only divisible by 1 and itself. Example 1: ...

January 2, 2023 · 2 分鐘 · Rain Hu

[LeetCode] 520. Detect Capital

520. Detect Capital Hardness: \(\color{green}\textsf{Easy}\) Ralated Topics: String 一、題目 We define the usage of capitals in a word to be right when one of the following cases holds: All letters in this word are capitals, like "USA". All letters in this word are not capitals, like "leetcode". Only the first letter in this word is capital, like "Google". Given a string word, return true if the usage of capitals in it is right. Example 1: ...

January 2, 2023 · 2 分鐘 · Rain Hu

[LeetCode] 2521. Distinct Prime Factors of Product of Array

2521. Distinct Prime Factors of Product of Array Hardness: \(\color{orange}\textsf{Medium}\) Ralated Topics: \(\color{blue}\textsf{Weekly Contest 323}\) 一、題目 Given an array of positive integers nums, return the number of distinct prime factors in the product of the elements of nums. Note that: A number greater than 1 is called prime if it is divisible by only 1 and itself. An integer val1 is a factor of another integer val2 if val2 / val1 is an integer. Example 1: ...

January 1, 2023 · 2 分鐘 · Rain Hu

[LeetCode] 2520. Count the Digits That Divide a Number

2520. Count the Digits That Divide a Number Hardness: \(\color{green}\textsf{Easy}\) Ralated Topics: \(\color{blue}\textsf{Weekly Contest 323}\) 一、題目 Given an integer num, return the number of digits in num that divide num. An integer val divides nums if nums % val == 0. Example 1: Input: num = 7 Output: 1 Explanation: 7 divides itself, hence the answer is 1. Example 2: Input: num = 121 Output: 2 Explanation: 121 is divisible by 1, but not 2. Since 1 occurs twice as a digit, we return 2. Example 3: ...

January 1, 2023 · 1 分鐘 · Rain Hu

[LeetCode] 290. Word Pattern

290. Word Pattern Hardness: \(\color{green}\textsf{Easy}\) Ralated Topics: Hash Table、String 一、題目 Given a pattern and a string s, find if s follows the same pattern. Here follow means a full match, such that there is a bijection between a letter in pattern and non-empty word in s. Example 1: Input: pattern = “abba”, s = “dog cat cat dog” Output: true Example 2: Input: pattern = “abba”, s = “dog cat cat fish” Output: false Example 3: ...

January 1, 2023 · 2 分鐘 · Rain Hu

[LeetCode] 1834. Single-Threaded CPU

1834. Single-Threaded CPU Hardness: \(\color{orange}\textsf{Medium}\) Ralated Topics: Array、Sorting、Heap (Priority Queue> 一、題目 You are given n​​​​ tasks labeled from 0 to n - 1 represented by a 2D integer array tasks, where tasks[i] = [enqueueTimei, processingTimei] means that the i​​​​​​th​​​​ task will be available to process at enqueueTimei and will take processingTimei to finish processing. You have a single-threaded CPU that can process at most one task at a time and will act in the following way: ...

December 29, 2022 · 4 分鐘 · Rain Hu

[LeetCode] 1962. Remove Stones to Minimize the Total

1962. Remove Stones to Minimize the Total Hardness: \(\color{orange}\textsf{Medium}\) Ralated Topics: Array、Heap (Priority Queue) 一、題目 You are given a 0-indexed integer array piles, where piles[i] represents the number of stones in the ith pile, and an integer k. You should apply the following operation exactly k times: Choose any piles[i] and remove floor(piles[i] / 2) stones from it. Notice that you can apply the operation on the same pile more than once. Return the minimum possible total number of stones remaining after applying the k operations. floor(x) is the greatest integer that is smaller than or equal to x (i.e., rounds x down). ...

December 29, 2022 · 2 分鐘 · Rain Hu