Number of Ways to Arrive at Destination
1976. Number of Ways to Arrive at Destination
You are in a city that consists of n intersections numbered from 0 to n - 1 with bi-directional roads between some intersections. The inputs are generated such that you can reach any intersection from any other intersection and that there is at most one road between any two intersections.
You are g...
Minimum Time to Type Word Using Special Typewriter
1974. Minimum Time to Type Word Using Special Typewriter
There is a special typewriter with lowercase English letters ‘a’ to ‘z’ arranged in a circle with a pointer. A character can only be typed if the pointer is pointing to that character. The pointer is initially pointing to the character ‘a’.
Each second, you may perform one of the followi...
Maximum Matrix Sum
1975. Maximum Matrix Sum
You are given an n x n integer matrix. You can do the following operation any number of times:
Choose any two adjacent elements of matrix and multiply each of them by -1.
Two elements are considered adjacent if and only if they share a border.
Your goal is to maximize the summation of the matrix’s elements. Return the...
Sell Diminishing-Valued Colored Balls
1648. Sell Diminishing-Valued Colored Balls
You have an inventory of different colored balls, and there is a customer that wants orders balls of any color.
The customer weirdly values the colored balls. Each colored ball’s value is the number of balls of that color you currently have in your inventory. For example, if you own 6 yellow balls, th...
Minimum Deletions to Make Character Frequencies Unique
1647. Minimum Deletions to Make Character Frequencies Unique
A string s is called good if there are no two different characters in s that have the same frequency.
Given a string s, return the minimum number of characters you need to delete to make s good.
The frequency of a character in a string is the number of times it appears in the string....
Get Maximum in Generated Array
1646. Get Maximum in Generated Array
You are given an integer n. An array nums of length n + 1 is generated in the following way:
nums[0] = 0
nums[1] = 1
nums[2 * i] = nums[i] when 2 <= 2 * i <= n
nums[2 * i + 1] = nums[i] + nums[i + 1] when 2 <= 2 * i + 1 <= n
Return the maximum integer in the array nums.
Solution - Simulation
...
Merge Sorted Array
88. Merge Sorted Array
Solution
Reference
Notice that the empty slots are at the end of the array.
Start from the end of the array and travel towards the beginning of the array.
def merge(self, nums1, m, nums2, n):
"""
:type nums1: List[int]
:type m: int
:type nums2: List[int]
:type n: int
:rtype: N...
Basic Calculator II
227. Basic Calculator II
Solution
Reference
Use a stack to store the procedure, only nums are contained inside the stack, so that we can sum all in the end.
’+’ and ‘-‘ will result in positive and negative numbers.
‘*’ and ‘/’ requires the calculation with the previous number.
def calculate(self, s):
if not s...
199 post articles, 25 pages.