본문 바로가기
with my rubber duck/codingTest

[프로그래머스] 소수만들기 풀어보기

by stilinski 2022. 6. 22.
728x90
class Solution {
    public int solution(int[] nums) {
      
        int numsArrLength = nums.length;
        int cnt = 0;
		for (int i = 0; i < numsArrLength; i++) {
			for (int j = i + 1; j < numsArrLength; j++) {
				for (int h = j + 1; h < numsArrLength; h++) {
					int num = nums[i] + nums[j] + nums[h];
					for (int k = 2; k <= num; k++) {
						if ((num % k) == 0) {
							if(num==k) {
								cnt++;
							}else {
								break;
							}
						}
					}

				}

			}
		}
   
        return cnt;
    }
}

728x90

댓글