본문 바로가기

개발90

[LeetCode 1] Two Sum 안녕하십니까. Eun🦆입니다. 풀이법 입니다. Two Sum - 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 class Solution { public: vector twoSum(vector& nums, int target) { vector answer; for(int i=0;i 2022. 6. 7.
[프로그래머스 Lv3 C++] 야근 지수 안녕하십니까. Eun🦆입니다. 풀이법 입니다. 코딩테스트 연습 - 야근 지수 회사원 Demi는 가끔은 야근을 하는데요, 야근을 하면 야근 피로도가 쌓입니다. 야근 피로도는 야근을 시작한 시점에서 남은 일의 작업량을 제곱하여 더한 값입니다. Demi는 N시간 동안 야근 피로도 programmers.co.kr [효율성 미통과 코드] #include #include #include #include using namespace std; long long solution(int n, vector works) { long long answer = 0; for(int idx=0;idx 역시 n번 정렬은 안되나 싶다. ​ #include #include #include #include using namespace st.. 2022. 6. 7.
[프로그래머스 Lv3 C++] 멀리 뛰기 안녕하십니까. Eun🦆입니다. 풀이법 입니다. 코딩테스트 연습 - 멀리 뛰기 효진이는 멀리 뛰기를 연습하고 있습니다. 효진이는 한번에 1칸, 또는 2칸을 뛸 수 있습니다. 칸이 총 4개 있을 때, 효진이는 (1칸, 1칸, 1칸, 1칸) (1칸, 2칸, 1칸) (1칸, 1칸, 2칸) (2칸, 1칸, 1칸) (2칸, 2 programmers.co.kr #include #include #include long long solution(int n) { long long answer = 0; int a = 1; int b = 1; if(n==1) return 1; for(int idx=2;idx 2022. 6. 7.
[프로그래머스 Lv3 C++] 가장 긴 팰린드롬 안녕하십니까. Eun🦆입니다. 풀이법 입니다. 코딩테스트 연습 - 가장 긴 팰린드롬 앞뒤를 뒤집어도 똑같은 문자열을 팰린드롬(palindrome)이라고 합니다. 문자열 s가 주어질 때, s의 부분문자열(Substring)중 가장 긴 팰린드롬의 길이를 return 하는 solution 함수를 완성해 주세요. 예를들 programmers.co.kr #include #include #include ​ int solution(const char* s) { int answer_odd = 0; int answer_even = 0; //printf("len=%d\n",strlen(s)); // odd for(int idx=1;idx 2022. 6. 7.
[프로그래머스 Lv3 C++] 이중우선큐 안녕하십니까. Eun🦆입니다. 풀이법 입니다. 코딩테스트 연습 - 이중우선순위큐 programmers.co.kr #include #include #include using namespace std; vector solution(vector operations) { vector answer; vector queue; for(int idx=0;idx1) sort(queue.begin(), queue.end(), greater()); //printf("D 1:%d\n",queue[0]); if(queue.empty()==0) queue.erase(queue.begin()); } else if(operations[idx]=="D -1") { if(queue.size()>1) sort(queue.begin(), .. 2022. 6. 7.
[프로그래머스 Lv3 C++] 단어 변환 안녕하십니까. Eun🦆입니다. 풀이법 입니다. 코딩테스트 연습 - 단어 변환 두 개의 단어 begin, target과 단어의 집합 words가 있습니다. 아래와 같은 규칙을 이용하여 begin에서 target으로 변환하는 가장 짧은 변환 과정을 찾으려고 합니다. 1. 한 번에 한 개의 알파벳만 바꿀 수 programmers.co.kr #include #include using namespace std; int answer = 99; void dfs(string begin, string target, vector words, vector use, int cnt) { // 매번 들어올 때마다 글자가 한 개 다른 문자를 찾는다. for(int i=0;i 2022. 6. 7.