ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • 분수의 덧셈
    프로그래머스/LV.0 2024. 5. 14. 04:43
    class Solution {
        public int[] solution(int numer1, int denom1, int numer2, int denom2) {
            int[] answer = new int[2];
            
            
            int denom = denom1*denom2;
            int numer = (numer1*denom2) + (numer2*denom1);
            
            int GCD2 = GCD(numer, denom);
            
            answer[0]= numer/GCD2;
            answer[1] = denom/GCD2;
            
            return answer;
        }
                
            public int GCD(int a, int b) {
                if (a%b ==0) {
                    return b;
                } else {
                   return GCD(b, a%b);
                }  
            }
            
            
        }

     

     

    GCD메소드 종이에 풀면서 해봐 꼭

    댓글

Designed by Tistory.