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 44
55public class Solution {
66 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 ;
1111 int result = 0 ;
1212 for (char c : s .toCharArray ()) {
1313 if (c == 'N' ) {
14- n ++;
14+ north ++;
1515 } else if (c == 'S' ) {
16- s ++;
16+ south ++;
1717 } else if (c == 'E' ) {
18- e ++;
18+ east ++;
1919 } else if (c == 'W' ) {
20- w ++;
20+ west ++;
2121 }
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 );
2626 if (hMin + vMin >= k ) {
2727 int curr = hMax + vMax + k - (hMin + vMin - k );
2828 result = Math .max (result , curr );
You can’t perform that action at this time.
0 commit comments