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
Design an algorithm to encode a list of strings to a string. The encoded string is then sent over the network and is decoded back to the original list of strings.
12
+
13
+
## Examples
14
+
15
+
### Example 1:
16
+
17
+
```
18
+
Input: dummy_input = ["Hello","World"]
19
+
Output: "Hello,World"
20
+
Explanation: Machine 1:
21
+
Codec encoder = new Codec();
22
+
String msg = encoder.encode(strs);
23
+
Machine 1 ---msg---> Machine 2
24
+
Machine 2:
25
+
Codec decoder = new Codec();
26
+
String[] strs = decoder.decode(msg);
27
+
```
28
+
29
+
## Constraints
30
+
31
+
- 1 <= strs.length <= 200
32
+
- 0 <= strs[i].length <= 200
33
+
- strs[i] contains any possible characters out of 256 valid ASCII characters.
34
+
35
+
**Note:**
36
+
37
+
- The string may contain any possible characters out of 256 valid ASCII characters. Your algorithm should be generalized enough to work on any possible characters.
38
+
- Do not use class member/global/static variables to store states. Your encode and decode algorithms should be stateless.
39
+
- Do not rely on any library method such as eval or serialize methods. You should implement your own encode/decode algorithm.
Given `n` nodes labeled from `0` to `n-1` and a list of undirected edges (each edge is a pair of nodes), write a function to check whether these edges make up a valid tree.
12
+
13
+
## Examples
14
+
15
+
### Example 1:
16
+
17
+
```
18
+
Input: n = 5, and edges = [[0,1], [0,2], [0,3], [1,4]]
19
+
Output: true
20
+
```
21
+
22
+
### Example 2:
23
+
24
+
```
25
+
Input: n = 5, and edges = [[0,1], [1,2], [2,3], [1,3], [1,4]]
26
+
Output: false
27
+
```
28
+
29
+
## Constraints
30
+
31
+
- 0 <= n <= 2000
32
+
- 0 <= edges.length <= 5000
33
+
- edges[i].length == 2
34
+
- 0 <= ai, bi < n
35
+
- ai != bi
36
+
- There are no self-loops or repeated edges.
37
+
38
+
**Note:** you can assume that no duplicate edges will appear in edges. Since all edges are undirected, [0,1] is the same as [1,0] and thus will not appear together in edges.
0 commit comments