(leetcode) flipping-an-image , Java풀이

Sorbet·2021년 5월 26일
class Solution {
public int[][] flipAndInvertImage(int[][] image) {
        int[][] answer = new int[image.length][image[0].length];

        for(int i=0 ; i<image.length ; i++) {
            for(int j=0 ; j<image[i].length ; j++) {
                answer[i][j] = 1-image[i][image[i].length-1-j];
            }
        }


        return answer;
    }
}

코테기법

  • 1을0으로 & 0을 1로
    : output = 1-input
  • 아류작으로 N 차이 나는 두 수를 계속 스위칭하는데 쓸 수 있다
    : 예시) 1은 빨강팀, 2는 파랑팀이라서 오델로게임을 만드는데 스위칭하는 경우 적용 가능
    : output = 3-input

일반식

  • output = (output+input) - input
profile
Sorbet is good...!

0개의 댓글