일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | |
7 | 8 | 9 | 10 | 11 | 12 | 13 |
14 | 15 | 16 | 17 | 18 | 19 | 20 |
21 | 22 | 23 | 24 | 25 | 26 | 27 |
28 | 29 | 30 |
- condition
- loop
- vue.js
- npm
- var
- Python
- leetcode
- docker
- scss
- type
- security
- Clone
- git
- vuetify
- AI
- property
- generic
- TypeScript
- BOJ
- webpack
- VUE
- 앙상블
- 보안
- machine learning
- nginx
- C++
- JavaScript
- bash
- C#
- dotenv
- Today
- Total
목록PS (53)
ice rabbit programming
https://leetcode.com/problems/path-sum/ tree에서 root~leaf 까지의 합이 주어진 값과 일치하는 경우가 있는지 확인하는 문제이다. 학부생 시절 코딩테스트를 준비할 때에는 tree 문제를 아주 많이 풀었으나, 요즘에는 잘 풀지 않아 DFS라는 개념만 기억하고 있었다. 따로 예전의 스킬을 찾아 보지는 않고, 논리에 맞게 생각하면서 분기를 태웠다. 아래가 제출한 코드인데, 분기 코드가 좀 지저분하다. 주어진 TreeNode가 부모는 갖고 있지 않아 stack에 push/pop하면서 비교하고, 한 쪽만 비거나 양 쪽 모두 비었을 경우 모두를 분기하느라 분기 조건이 길어졌다. 이 문제 또한 요즘 C++을 사용하고 있어 문제도 C++로 풀어 보았다. /** * Definiti..
https://leetcode.com/problems/length-of-last-word 문제 구성은 매우 쉽게 이해할 수 있다. 띄어쓰기를 구분으로 주어지는 문장에서, 마지막 단어의 길이를 반환하면 된다. 금방 풀 수 있고, 연속해서 공백이 나오거나 앞뒤에 공백이 주어지는 점만 주의하면 된다. 본인은 공백을 기준으로 자르고, 마지막이 공백인 경우를 제외할 수 있도록 처리하였다. 근래에 계속 Python을 이용해서 풀다가, 요즘에는 현업에서 C++을 사용하고 있기에 C++로 풀어보았다. class Solution { public: int lengthOfLastWord(string s) { std::istringstream iss(s); std::vector tokens; std::string token;..
https://leetcode.com/problems/missing-number/ Missing Number - LeetCode Can you solve this real interview question? Missing Number - Given an array nums containing n distinct numbers in the range [0, n], return the only number in the range that is missing from the array. Example 1: Input: nums = [3,0,1] Output: 2 Explanatio leetcode.com 문제는 매우 직관적으로 이해할 수 있다. 중복이 없는 n 길이의 0~n 배열이 주어지는데, 이 중 한 숫자..
https://leetcode.com/problems/add-digits/description/ Add Digits - 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 처음에는 제목만 보고 이진수의 덧셈인 줄 알았는데, 그건 아니었다. 자연수가 주어지면, 각 자릿수의 합 결과가 한 자릿수가 될 때까지 계산하여 반환하는 문제이다. (ex. 76 -> 7+6 -> 13 -> 1+3 -> 4) 특별한 로직은 없었고, 거의 브루트 포스 하게 풀었다. 처음에 한 자릿수가 ..
https://leetcode.com/problems/implement-stack-using-queues/description/ Implement Stack using Queues - 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 이전에 스택으로 큐 구현하기와 유사한데, 큐 두 개를 사용한다는 발상은 똑같지만, 학생 때 취준하면서 스택으로 큐 구현하기는 몇 번 해 봤었는데 거꾸로는 처음한 것 같았다. 로직은 이전과 같이 특이한 점이 없기 때문에, 아래 코드를 보..
https://leetcode.com/problems/implement-queue-using-stacks/description/ Implement Queue using Stacks - 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 주니어 코테나 면접에서 상당히 자주 등장하는, 스택으로 큐 구현하기이다. 스택 두 개를 활용하면 어렵지 않게 구현할 수 있다. 로직 자체는 어렵지 않으니 아래 코드를 보면 이해가 갈 것이다. 문제 자체도 제네릭(템플릿)한 것이 아니라 ..
https://leetcode.com/problems/toeplitz-matrix/description/ Toeplitz Matrix - 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 우하향하는 대각선에 있는 원소들이 모두 같은 값을 가지는지 체크하는 문제이다. 별다른 로직은 사용하지 않았고 단순하게 1행 1열~1행 끝열까지 가면서 본인의 대각선 아래가 같은 값인지 체크하도록 하였다. 사실상 브루트 포스한 풀이라 시간이 오래 걸릴 줄 알았는데 제출 답변 중에 9..
https://leetcode.com/problems/valid-anagram/ Valid Anagram - 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 간만에 문제풀이를 하여 포스팅하게 되었다. 문제는 간단한 편이다. Anagram 문자열인지를 확인하는 문제로, 두 문자열이 주어지고, 순서와는 관계 없이 사용된 문자가 일치하면 된다. ex) "anagram"과 "aganram" 여러 방법이 있을 것 같으나, 본인은 Map을 이용하여 사용된 문자 개수를 증감시..