You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A string s is valid if, starting with an empty string t = "", you can transform t into s after performing the following operation any number of times:
6
+
7
+
Insert string "abc" into any position in t. More formally, t becomes tleft + "abc" + tright, where t == tleft + tright. Note that tleft and tright may be empty.
8
+
Return true if s is a valid string, otherwise, return false.
We make a clumsy factorial using the integers in decreasing order by swapping out the multiply operations for a fixed rotation of operations with multiply '*', divide '/', add '+', and subtract '-' in this order.
However, these operations are still applied using the usual order of operations of arithmetic. We do all multiplication and division steps before any addition or subtraction steps, and multiplication and division steps are processed left to right.
10
+
11
+
Additionally, the division that we use is floor division such that 10 * 9 / 8 = 90 / 8 = 11.
12
+
13
+
Given an integer n, return the clumsy factorial of n.
In a row of dominoes, tops[i] and bottoms[i] represent the top and bottom halves of the ith domino. (A domino is a tile with two numbers from 1 to 6 - one on each half of the tile.)
4
+
5
+
We may rotate the ith domino, so that tops[i] and bottoms[i] swap values.
6
+
7
+
Return the minimum number of rotations so that all the values in tops are the same, or all the values in bottoms are the same.
Given a positive integer k, you need to find the length of the smallest positive integer n such that n is divisible by k, and n only contains the digit 1.
4
+
5
+
Return the length of n. If there is no such n, return -1.
6
+
7
+
Note: n may not fit in a 64-bit signed integer.
8
+
9
+
10
+
11
+
Example 1:
12
+
13
+
Input: k = 1
14
+
Output: 1
15
+
Explanation: The smallest answer is n = 1, which has length 1.
16
+
Example 2:
17
+
18
+
Input: k = 2
19
+
Output: -1
20
+
Explanation: There is no such positive integer n divisible by 2.
21
+
Example 3:
22
+
23
+
Input: k = 3
24
+
Output: 3
25
+
Explanation: The smallest answer is n = 111, which has length 3.
Given a binary string s and a positive integer n, return true if the binary representation of all the integers in the range [1, n] are substrings of s, or false otherwise.
4
+
5
+
A substring is a contiguous sequence of characters within a string.
6
+
7
+
Example 1:
8
+
9
+
Input: s = "0110", n = 3
10
+
Output: true
11
+
Example 2:
12
+
13
+
Input: s = "0110", n = 4
14
+
Output: false
15
+
16
+
17
+
Constraints:
18
+
19
+
1 <= s.length <= 1000
20
+
s[i] is either '0' or '1'.
21
+
1 <= n <= 10^9
22
+
"""
23
+
24
+
classSolution:
25
+
defqueryString(self, s: str, n: int) ->bool:
26
+
"""
27
+
Naive solution: KMP string matching from 1 to N, O(N * (m + n)).
0 commit comments