반응형
    
    
    
  https://leetcode.com/problems/flipping-an-image/description/
Flipping an Image - LeetCode
Can you solve this real interview question? Flipping an Image - Given an n x n binary matrix image, flip the image horizontally, then invert it, and return the resulting image. To flip an image horizontally means that each row of the image is reversed. * F
leetcode.com
구현 문제였습니다.
📕 풀이방법
📔 풀이과정
요구사항 그대로 구현해줍니다.1. 행을 수평으로 뒤집어줍니다.2. images의 각 원소를 flip해줍니다.
📔 정답 출력 | 반환
image를 반환합니다.
📕 Code
📔 C++
class Solution {
public:
    void reverseHorizontally(vector<vector<int>> &image){
        for(auto &im : image) {
            reverse(im.begin(),im.end());
        }
    }
    void flipHorizontally(vector<vector<int>> &image) {
        for(auto &im : image) {
            for(auto &i : im) {
                i = !i;
            }
        }
    }
    vector<vector<int>> flipAndInvertImage(vector<vector<int>>& image) {
        reverseHorizontally(image);
        flipHorizontally(image);
        return image;
    }
};*더 나은 내용을 위한 지적, 조언은 언제나 환영합니다.
'Algorithm > Implementation' 카테고리의 다른 글
| (C++) - LeetCode (easy) 860. Lemonade Change (0) | 2023.08.02 | 
|---|---|
| (C++) - LeetCode (easy) 836. Rectangle Overlap (0) | 2023.07.27 | 
| (C++) - LeetCode (easy) 830. Positions of Large Groups (0) | 2023.07.25 | 
| (C++) - LeetCode (easy) 819. Most Common Word (0) | 2023.07.21 | 
| (C++) - LeetCode (easy) 806. Number of Lines To Write String (0) | 2023.07.17 |