[프로그래머스, 181839] 주사위 게임 1 (java)
Problem Solving/Programmers

[프로그래머스, 181839] 주사위 게임 1 (java)

728x90

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

 

프로그래머스

SW개발자를 위한 평가, 교육, 채용까지 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프

programmers.co.kr


메모리: 79.6 MB, 시간: 0.06 ms

사용 알고리즘: 구현

class Solution {
    public int solution(int a, int b) {
        if(a % 2 == 1 && b % 2 == 1)
            return (int)Math.pow(a, 2) + (int)Math.pow(b, 2);
        else if(a % 2 == 0 && b % 2 == 0)
            return Math.abs(a - b);
        else
            return 2 * (a + b);
    }
}
728x90