1. 문제풀이
두 배열의 정보를 비트 연산자로 비교해 둘 중 하나라도 1이면 '#'을 아니면 ' '을 삽입하며 풀이하였다. 시간복잡도는 O(n^2)이다.
2. 코드
#include <bits/stdc++.h>
using namespace std;
vector<string> solution(int n, vector<int> A, vector<int> B) {
vector<string> ans(n);
cout << ans[0] << '\n';
for(int i = 0; i < n; i++){
for(int j = n-1; j >= 0; j--){
if(((A[i] >> j) & 1) | ((B[i] >> j) & 1)) ans[i].push_back('#');
else ans[i].push_back(' ');
}
}
return ans;
}
3. 제출 결과
'알고리즘 > 프로그래머스' 카테고리의 다른 글
프로그래머스 Level3 단속카메라[C++] (0) | 2025.01.04 |
---|---|
프로그래머스 Level3: 숫자게임[C++] (0) | 2025.01.03 |
프로그래머스 Level 3: 단어 변환[C++] (0) | 2025.01.01 |
프로그래머스 Level 3: 야근 지수 (0) | 2024.12.04 |
프로그래머스 Level1: 숫자 문자열과 영단어[C++] (0) | 2024.10.14 |