Skip to content

Commit 0adde4a

Browse files
committed
[level 2] Title: 조이스틱, Time: 0.23 ms, Memory: 82.4 MB -BaekjoonHub
1 parent 17578fe commit 0adde4a

File tree

2 files changed

+23
-23
lines changed

2 files changed

+23
-23
lines changed

프로그래머스/2/42860. 조이스틱/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
### 성능 요약
66

7-
메모리: 85.9 MB, 시간: 0.23 ms
7+
메모리: 82.4 MB, 시간: 0.23 ms
88

99
### 구분
1010

@@ -16,7 +16,7 @@
1616

1717
### 제출 일자
1818

19-
2025년 09월 13일 11:29:30
19+
2025년 09월 16일 11:06:45
2020

2121
### 문제 설명
2222

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,34 @@
11
import java.util.*;
22
class Solution {
33
public int solution(String name) {
4-
int upDown = 0;
5-
for(char ch : name.toCharArray()){
6-
upDown += Math.min(ch - 'A','Z' - ch + 1);
4+
int upDown = 0;
5+
6+
for(char ch : name.toCharArray()) {
7+
upDown += Math.min(ch - 'A', 'Z' - ch + 1);
78
}
89
System.out.println(upDown);
910

10-
char[] names = name.toCharArray();
11-
int leftRight = name.length() - 1; // 기본값: 오른쪽으로 쭉 직진
12-
// 1. 왼쪽 찍고 오른쪽으로 다시 도착
13-
// 2. 오른쪽 찍고 왼쪽으로 다시 도착
14-
// 3. 왼쪽으로 쭉 직진 , 오른쪽으로 쭉 직진
15-
11+
char[] ch = name.toCharArray();
1612
int len = name.length();
17-
for(int i = 0; i < len ; i++) {
18-
int next = i + 1;
19-
20-
while(next < len && names[next] == 'A'){
21-
next ++;
13+
int leftRight = len - 1;
14+
for(int i = 0; i < len; i++) {
15+
int next = i+1;
16+
while(next < len && ch[next] == 'A'){
17+
next++;
2218
}
19+
// len = 9
20+
// next = 7
21+
// JAAAAAABB
22+
23+
// 왼쪽 찍고, 오른쪽으로
24+
int left = i * 2 + len - next;
25+
// 오른쪽 돌아서 찍고, 다시 왼쪽으로
26+
int right = (len - next) * 2 + i;
2327

24-
// 1번
25-
int temp1 = (len - next) * 2 + i;
26-
// 2번
27-
int temp2 = (i * 2) + len-next;
28-
leftRight = Math.min(leftRight,Math.min(temp1,temp2));
28+
int min = Math.min(left,right);
29+
leftRight = Math.min(min,leftRight);
2930
}
3031

31-
int answer = leftRight + upDown;
32-
return answer;
32+
return upDown + leftRight;
3333
}
3434
}

0 commit comments

Comments
 (0)