Algorithm/Programmers

[Programmers] Lv.0 / 수 조작하기 1 / Java

unknownomad 2023. 10. 18. 00:05

문제

 

풀이

class Solution {
    public int solution(int n, String control) {
        char[] charArray = control.toCharArray();
        
        for(Character ch : charArray) {
            if(ch.equals('w')) {
                n += 1;
            } else if(ch.equals('s')) {
                n -= 1;
            } else if(ch.equals('d')) {
                n += 10;
            } else if(ch.equals('a')) {
                n -= 10;
            }
        }
        return n;
    }
}
class Solution {
    public int solution(int n, String control) {
        for (char ch : control.toCharArray()) {
            if (ch == 'w') n += 1;
            else if (ch == 's') n -= 1;
            else if (ch == 'd') n += 10;
            else n -= 10;
        }
        return n;
    }
}

 

출처

https://school.programmers.co.kr/learn/courses/30/lessons/181926