File tree Expand file tree Collapse file tree 1 file changed +12
-12
lines changed
src/main/java/g3401_3500/s3443_maximum_manhattan_distance_after_k_changes Expand file tree Collapse file tree 1 file changed +12
-12
lines changed Original file line number Diff line number Diff line change 4
4
5
5
public class Solution {
6
6
public int maxDistance (String s , int k ) {
7
- int n = 0 ;
8
- int s = 0 ;
9
- int w = 0 ;
10
- int e = 0 ;
7
+ int north = 0 ;
8
+ int south = 0 ;
9
+ int west = 0 ;
10
+ int east = 0 ;
11
11
int result = 0 ;
12
12
for (char c : s .toCharArray ()) {
13
13
if (c == 'N' ) {
14
- n ++;
14
+ north ++;
15
15
} else if (c == 'S' ) {
16
- s ++;
16
+ south ++;
17
17
} else if (c == 'E' ) {
18
- e ++;
18
+ east ++;
19
19
} else if (c == 'W' ) {
20
- w ++;
20
+ west ++;
21
21
}
22
- int hMax = Math .max (n , s );
23
- int vMax = Math .max (w , e );
24
- int hMin = Math .min (n , s );
25
- int vMin = Math .min (w , e );
22
+ int hMax = Math .max (north , south );
23
+ int vMax = Math .max (west , east );
24
+ int hMin = Math .min (north , south );
25
+ int vMin = Math .min (west , east );
26
26
if (hMin + vMin >= k ) {
27
27
int curr = hMax + vMax + k - (hMin + vMin - k );
28
28
result = Math .max (result , curr );
You can’t perform that action at this time.
0 commit comments