알고리즘 0레벨 풀이 - 3/13

송현진·2023년 3월 13일
0

알고리즘

목록 보기
1/50
post-thumbnail
  • 나이 구하기
class Solution {
    public int solution(int age) {
        int answer = 0;
        answer = 2022 - age +1;
        return answer;
    }
}
  • 숫자 비교하기
class Solution {
    public int solution(int num1, int num2) {
        return num1 == num2 ? 1 : -1;
    }
}
  • 짝수의 합
class Solution {
    public int solution(int n) {
        int answer = 0;
        for(int i = 0; i <= n; i++){
            if(i%2 == 0){
                answer += i;
            }
        }
        return answer;
    }
}
  • 각도기
class Solution {
    public int solution(int angle) {
        if(0 < angle && angle < 90){
            return 1;
        }else if(angle == 90){
            return 2;
        }else if(90 < angle && angle < 180){
            return 3;
        }else{
            return 4;
        }
    }
}

아직까진 어려운 부분은 없었다. 어떻게 하면 코드가 더 간결하고
가독성이 좋아질 수 있을까라는 생각중이다.

profile
개발자가 되고 싶은 취준생

0개의 댓글