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
An **n-bit gray code sequence** is a sequence of <code>2<sup>n</sup></code> integers where:
6
+
7
+
* Every integer is in the **inclusive** range <code>[0, 2<sup>n</sup> - 1]</code>,
8
+
* The first integer is `0`,
9
+
* An integer appears **no more than once** in the sequence,
10
+
* The binary representation of every pair of **adjacent** integers differs by **exactly one bit**, and
11
+
* The binary representation of the **first** and **last** integers differs by **exactly one bit**.
12
+
13
+
Given an integer `n`, return _any valid **n-bit gray code sequence**_.
14
+
15
+
**Example 1:**
16
+
17
+
**Input:** n = 2
18
+
19
+
**Output:**[0,1,3,2]
20
+
21
+
**Explanation:** The binary representation of [0,1,3,2] is [00,01,11,10]. - 0<ins>0</ins> and 0<ins>1</ins> differ by one bit - <ins>0</ins>1 and <ins>1</ins>1 differ by one bit - 1<ins>1</ins> and 1<ins>0</ins> differ by one bit - <ins>1</ins>0 and <ins>0</ins>0 differ by one bit [0,2,3,1] is also a valid gray code sequence, whose binary representation is [00,10,11,01]. - <ins>0</ins>0 and <ins>1</ins>0 differ by one bit - 1<ins>0</ins> and 1<ins>1</ins> differ by one bit - <ins>1</ins>1 and <ins>0</ins>1 differ by one bit - 0<ins>1</ins> and 0<ins>0</ins> differ by one bit
A message containing letters from `A-Z` can be **encoded** into numbers using the following mapping:
6
+
7
+
'A' -> "1" 'B' -> "2" ... 'Z' -> "26"
8
+
9
+
To **decode** an encoded message, all the digits must be grouped then mapped back into letters using the reverse of the mapping above (there may be multiple ways). For example, `"11106"` can be mapped into:
10
+
11
+
*`"AAJF"` with the grouping `(1 1 10 6)`
12
+
*`"KJF"` with the grouping `(11 10 6)`
13
+
14
+
Note that the grouping `(1 11 06)` is invalid because `"06"` cannot be mapped into `'F'` since `"6"` is different from `"06"`.
15
+
16
+
Given a string `s` containing only digits, return _the **number** of ways to **decode** it_.
17
+
18
+
The test cases are generated so that the answer fits in a **32-bit** integer.
19
+
20
+
**Example 1:**
21
+
22
+
**Input:** s = "12"
23
+
24
+
**Output:** 2
25
+
26
+
**Explanation:** "12" could be decoded as "AB" (1 2) or "L" (12).
27
+
28
+
**Example 2:**
29
+
30
+
**Input:** s = "226"
31
+
32
+
**Output:** 3
33
+
34
+
**Explanation:** "226" could be decoded as "BZ" (2 26), "VF" (22 6), or "BBF" (2 2 6).
35
+
36
+
**Example 3:**
37
+
38
+
**Input:** s = "06"
39
+
40
+
**Output:** 0
41
+
42
+
**Explanation:** "06" cannot be mapped to "F" because of the leading zero ("6" is different from "06").
43
+
44
+
**Constraints:**
45
+
46
+
*`1 <= s.length <= 100`
47
+
*`s` contains only digits and may contain leading zero(s).
Given the `head` of a singly linked list and two integers `left` and `right` where `left <= right`, reverse the nodes of the list from position `left` to position `right`, and return _the reversed list_.
0 commit comments