https://programmers.co.kr/learn/courses/30/lessons/62048 코딩테스트 연습 - 멀쩡한 사각형 가로 길이가 Wcm, 세로 길이가 Hcm인 직사각형 종이가 있습니다. 종이에는 가로, 세로 방향과 평행하게 격자 형태로 선이 그어져 있으며, 모든 격자칸은 1cm x 1cm 크기입니다. 이 종이를 격자 선을 programmers.co.kr [프로그래머스] 멀쩡한 사각형 처음에 문제에서 규칙을 찾는게 좀 어려웠던 문제.. gcd라는 최대공약수를 찾는 함수도 있다는 걸 알게 됨 #include using namespace std; long long solution(int w, int h) { long long answer = 1; long long g = gcd(w, h);..
https://programmers.co.kr/learn/courses/30/lessons/12899 코딩테스트 연습 - 124 나라의 숫자 programmers.co.kr [programmers] 124 나라의 숫자 #include #include using namespace std; string solution(int n) { string answer = ""; if (n == 0) return answer; int nam = n % 3; int mok = n / 3; if (nam == 0) answer = solution(mok - 1) + "4"; else if (nam == 2) answer = solution(mok) + "2"; else answer = solution(mok) + "1";..
https://leetcode.com/problems/rotate-image/ Rotate Image - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com [leetcode][C++] rotate image 처음엔 노가다 구현을 했지만.. 배열을 시계방향으로 90도 회전 = 대각선 대칭 값 변경 + 좌우 대칭 값 변경 1 2 3 4 5 6 7 8 9 ↓ 대각선 대칭 값 변경 1 4 7 2 5 8 3 6 9 ↓ 좌우 대칭 값 변경 7 4 1 8 5 2 9 6 3 이렇..
https://www.acmicpc.net/problem/17779 17779번: 게리맨더링 2 재현시의 시장 구재현은 지난 몇 년간 게리맨더링을 통해서 자신의 당에게 유리하게 선거구를 획정했다. 견제할 권력이 없어진 구재현은 권력을 매우 부당하게 행사했고, 심지어는 시의 이름 www.acmicpc.net [백준][C++] 17779 게리맨더링2 #include #include #include using namespace std; int A[22][22] = {}; bool B[22][22] = {}; int N; void border(int x, int y, int d1, int d2) { int dx[4] = { 1,1,-1,-1 }; int dy[4] = { -1,1,1,-1 }; memset(B,..
https://leetcode.com/problems/sort-colors/ Sort Colors - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com [leetcode][C++] sort colors class Solution { public: void sortColors(vector& nums) { int low = 0; int high = nums.size() - 1; for (int i = 0; i
https://leetcode.com/problems/jump-game/ Jump Game - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com [leetcode][C++][Java] jump game 처음 보자마자 생각난건 dp.. greedy로 풀면 코드도 간결하고 java로도 1ms가 나온다. C++ // greedy class Solution { public: bool canJump(vector& nums) { int last = nums.size() - 1..
https://leetcode.com/problems/search-in-rotated-sorted-array/ Search in Rotated Sorted Array - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com input값은 정렬된 배열이기 때문에 바이너리 서치를 사용할 수 있다. 배열이 시작하는 시점 (정렬이 끝나는 시점)을 찾아서 범위마다 바이너리 서치를 실행해서 풀었다. nums[] = {5 1 < 2 < 3 < 4} binarySe..
https://leetcode.com/problems/generate-parentheses/ Generate Parentheses - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com [leetcode][C++] generate parentheses class Solution { public: void dfs(int l, int r, int n, string s, vector& ret) { if (l == n && r == n) { ret.push_back(s); ..