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
- 然后process当下col时候, sum += colValue * N - sumRow. 就等于把交叉所有row(曾经Process过的row)的点减去了。很方便。
11
+
- 最后readin是O(P), process也是O(P).
11
12
12
13
13
14
```
@@ -16,7 +17,9 @@
16
17
HackerRank.
17
18
You are given an N×NN×N grid. Each cell has the color white (color 0) in the beginning.
18
19
19
-
Each row and column has a certain color associated with it. Filling a row or column with a new color VV means changing all the cells of that row or column to VV (thus overriding the previous colors of the cells).
20
+
Each row and column has a certain color associated with it.
21
+
Filling a row or column with a new color VV means changing all the cells of
22
+
that row or column to VV (thus overriding the previous colors of the cells).
20
23
21
24
Now, given a sequence of PP such operations, calculate the sum of the colors in the final grid.
Given n non-negative integers a1, a2, ..., an, where each represents a point at coordinate (i, ai). n vertical lines are drawn such that the two endpoints of line i is at (i, ai) and (i, 0). Find two lines, which together with x-axis forms a container, such that the container contains the most water.
13
+
Given n non-negative integers a1, a2, ..., an,
14
+
where each represents a point at coordinate (i, ai).
15
+
n vertical lines are drawn such that the two endpoints of line i is at (i, ai) and (i, 0).
16
+
Find two lines, which together with x-axis forms a container,
17
+
such that the container contains the most water.
9
18
10
19
Example
11
20
Given [1,3,2], the max area of the container is 2.
@@ -27,10 +36,6 @@
27
36
On the other hand, if lett wall > right wall, right--.
28
37
*/
29
38
publicclassSolution {
30
-
/**
31
-
* @param heights: an array of integers
32
-
* @return: an integer
33
-
*/
34
39
publicintmaxArea(int[] heights) {
35
40
if (heights == null || heights.length == 0) {
36
41
return0;
@@ -39,7 +44,8 @@ public int maxArea(int[] heights) {
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.
15
+
Design an algorithm to encode a list of strings to a string.
16
+
The encoded string is then sent over the network and is decoded back to the original list of strings.
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.
42
-
Do not use class member/global/static variables to store states. Your encode and decode algorithms should be stateless.
43
-
Do not rely on any library method such as eval or serialize methods. You should implement your own encode/decode algorithm.
40
+
The string may contain any possible characters out of 256 valid ascii characters.
41
+
Your algorithm should be generalized enough to work on any possible characters.
44
42
43
+
Do not use class member/global/static variables to store states.
44
+
Your encode and decode algorithms should be stateless.
45
45
46
-
Tags: String
47
-
Similar Problems: (E) Count and Say, (M) Serialize and Deserialize Binary Tree
48
-
46
+
Do not rely on any library method such as eval or serialize methods.
47
+
You should implement your own encode/decode algorithm.
49
48
*/
50
49
51
50
52
51
/*
53
-
Recap 3.28.2016
54
-
Use number+"#" to mark a string. Append them all.
52
+
Use word.length() + "#" + word to mark a string. Append them all.
55
53
*/
56
54
publicclassCodec {
57
55
@@ -69,7 +67,7 @@ public String encode(List<String> strs) {
69
67
70
68
// Decodes a single string to a list of strings.
71
69
publicList<String> decode(Strings) {
72
-
List<String> strs = new ArrayList<String>();
70
+
List<String> strs = newArrayList<>();
73
71
if (s == null || s.length() == 0) {
74
72
returnstrs;
75
73
}
@@ -78,9 +76,9 @@ public List<String> decode(String s) {
0 commit comments