[LeetCode] 2470. Number of Subarrays With LCM Equal to K

2470. Number of Subarrays With LCM Equal to K Hardness: \(\color{orange}\textsf{Medium}\) Ralated Topics: Array、Math、Number Theory \(\color{blue}\textsf{weekly Contest 319}\) 一、題目 Given an integer array nums and an integer k, return the number of subarrays of nums where the least common multiple of the subarray’s elements is k. A subarray is a contiguous non-empty sequence of elements within an array. The least common multiple of an array is the smallest positive integer that is divisible by all the array elements. ...

<span title='2022-11-29 23:55:18 +0800 +0800'>November 29, 2022</span>&nbsp;·&nbsp;2 min&nbsp;·&nbsp;Rain Hu

[LeetCode] 2469. Convert the Temperature

2469. Convert the Temperature Hardness: \(\color{green}\textsf{Easy}\) Ralated Topics: Math \(\color{blue}\textsf{weekly Contest 319}\) 一、題目 You are given a non-negative floating point number rounded to two decimal places celsius, that denotes the temperature in Celsius. You should convert Celsius into Kelvin and Fahrenheit and return it as an array ans = [kelvin, fahrenheit]. Return the array ans. Answers within 10^-5 of the actual answer will be accepted. Note that: Kelvin = Celsius + 273.15 Fahrenheit = Celsius * 1.80 + 32.00 Example 1: ...

<span title='2022-11-29 23:55:11 +0800 +0800'>November 29, 2022</span>&nbsp;·&nbsp;1 min&nbsp;·&nbsp;Rain Hu

[LeetCode] 446. Arithmetic Slices II - Subsequence

446. Arithmetic Slices II - Subsequence Hardness: \(\color{red}\textsf{Hard}\) Ralated Topics: Array、Dynamic Programming 一、題目 Given an integer array nums, return the number of all the arithmetic subsequences of nums. A sequence of numbers is called arithmetic if it consists of at least three elements and if the difference between any two consecutive elements is the same. For example, [1, 3, 5, 7, 9], [7, 7, 7, 7], and [3, -1, -5, -9] are arithmetic sequences. For example, [1, 1, 2, 5, 7] is not an arithmetic sequence. A subsequence of an array is a sequence that can be formed by removing some elements (possibly none) of the array. For example, [2,5,10] is a subsequence of [1,2,1,2,4,1,5,10]. The test cases are generated so that the answer fits in 32-bit integer. Example 1: ...

<span title='2022-11-28 23:39:03 +0800 +0800'>November 28, 2022</span>&nbsp;·&nbsp;2 min&nbsp;·&nbsp;Rain Hu

[LeetCode] 2488. Count Subarrays With Median K

2488. Count Subarrays With Median K Hardness: \(\color{red}\textsf{Hard}\) Ralated Topics: Array、Hash Table、Prefix Sum \(\color{blue}\textsf{Weekly Contest 321}\) 一、題目 You are given an array nums of size n consisting of distinct integers from 1 to n and a positive integer k. Return the number of non-empty subarrays in nums that have a median equal to k. Note: The median of an array is the middle element after sorting the array in ascending order. If the array is of even length, the median is the left middle element. For example, the median of [2,3,1,4] is 2, and the median of [8,4,3,5,1] is 4. A subarray is a contiguous part of an array. Example 1: ...

<span title='2022-11-27 21:04:55 +0800 +0800'>November 27, 2022</span>&nbsp;·&nbsp;2 min&nbsp;·&nbsp;Rain Hu

[LeetCode] 2487. Remove Nodes From Linked List

2487. Remove Nodes From Linked List Hardness: \(\color{orange}\textsf{Medium}\) Ralated Topics: Linked List、Stack、Recursion、Monotonic Stack \(\color{blue}\textsf{Weekly Contest 321}\) 一、題目 You are given the head of a linked list. Remove every node which has a node with strictly greater value anywhere to the right side of it. Return the head of the modified linked list. Example 1: Input: head = [5,2,13,3,8] Output: [13,8] Explanation: The nodes that should be removed are 5, 2 and 3. Node 13 is to the right of node 5. Node 13 is to the right of node 2. Node 8 is to the right of node 3. Example 2: ...

<span title='2022-11-27 21:04:51 +0800 +0800'>November 27, 2022</span>&nbsp;·&nbsp;2 min&nbsp;·&nbsp;Rain Hu

[LeetCode] 2486. Accept Characters to String to Make Subsequence

2486. Accept Characters to String to Make Subsequence Hardness: \(\color{orange}\textsf{Medium}\) Ralated Topics: Two Pointer、String、Greedy \(\color{blue}\textsf{Weekly Contest 321}\) 一、題目 You are given two strings s and t consisting of only lowercase English letters. Return the minimum number of characters that need to be appended to the end of s so that t becomes a subsequence of s. A subsequence is a string that can be derived from another string by deleting some or no characters without changing the order of the remaining characters. ...

<span title='2022-11-27 21:04:50 +0800 +0800'>November 27, 2022</span>&nbsp;·&nbsp;2 min&nbsp;·&nbsp;Rain Hu

[LeetCode] 2485. Find the Pivot Integer

2485. Find the Pivot Integer Hardness: \(\color{green}\textsf{Easy}\) Ralated Topics: Math、Prefix Sum \(\color{blue}\textsf{Weekly Contest 321}\) 一、題目 Given a positive integer n, find the pivot integer x such that: The sum of all elements between 1 and x inclusively equals the sum of all elements between x and n inclusively. Return the pivot integer x. If no such integer exists, return -1. It is guaranteed that there will be at most one pivot index for the given input. Example 1: ...

<span title='2022-11-27 21:04:47 +0800 +0800'>November 27, 2022</span>&nbsp;·&nbsp;2 min&nbsp;·&nbsp;Rain Hu

[LeetCode] 1235. Maximum Profit in Job Scheduling

1235. Maximum Profit in Job Scheduling Hardness: \(\color{red}\textsf{Hard}\) Ralated Topics: Array、Binary Search、Dynamic Programming、Sorting 一、題目 We have n jobs, where every job is scheduled to be done from startTime[i] to endTime[i], obtaining a profit of profit[i]. You’re given the startTime, endTime and profit arrays, return the maximum profit you can take such that there are no two jobs in the subset with overlapping time range. If you choose a job that ends at time X you will be able to start another job that starts at time X. ...

<span title='2022-11-26 14:09:56 +0800 +0800'>November 26, 2022</span>&nbsp;·&nbsp;3 min&nbsp;·&nbsp;Rain Hu

[LeetCode] 1143. Longest Common Subsequence

1143. Longest Common Subsequence Hardness: \(\color{orange}\textsf{Medium}\) Ralated Topics: String、Dynamic Programming 一、題目 Given two strings text1 and text2, return the length of their longest common subsequence. If there is no common subsequence, return 0. A subsequence of a string is a new string generated from the original string with some characters (can be none) deleted without changing the relative order of the remaining characters. For example, "ace" is a subsequence of "abcde". A common subsequence of two strings is a subsequence that is common to both strings. Example 1: ...

<span title='2022-11-24 23:15:24 +0800 +0800'>November 24, 2022</span>&nbsp;·&nbsp;2 min&nbsp;·&nbsp;Rain Hu

[LeetCode] 300. Longest Increasing Subsequence

300. Longest Increasing Subsequence Hardness: \(\color{orange}\textsf{Medium}\) Ralated Topics: Array、Binary Search、Dynamic Programming 一、題目 Given an integer array nums, return the length of the longest strictly increasing subsequence Example 1: Input: nums = [10,9,2,5,3,7,101,18] Output: 4 Explanation: The longest increasing subsequence is [2,3,7,101], therefore the length is 4. Example 2: Input: nums = [0,1,0,3,2,3] Output: 4 Example 3: Input: nums = [7,7,7,7,7,7,7] Output: 1 Constraints: 1 <= nums.length <= 2500 -104 <= nums[i] <= 104 Follow up: Can you come up with an algorithm that runs in O(n log n) time complexity ...

<span title='2022-11-24 20:59:40 +0800 +0800'>November 24, 2022</span>&nbsp;·&nbsp;2 min&nbsp;·&nbsp;Rain Hu