본문 바로가기

카테고리 없음

알고리즘 (Algorithm) 참고모음

 

 

1.  n사이즈의 배열 +   각 요소의 값 0~3까지 일경우 burute force탐색

 

for (int i = 0; i < Math.pow(n, 4); i++) {
   int temp = i;
   for (int col = 0; col < n; col++) {
        int rotateCnt = temp % 4;
        temp /= 4;
        System.out.print(temp + ",");
    }
    System.out.println();
}

 


 

2. n * n 오버플로우

 

int x = 50000;
long result = x * x; // ❌ 여기서 x * x는 int 연산!

 

=> Math.pow(x, 2)는 내부에서 double로 계산