전체 글 (2344) 썸네일형 리스트형 (C++) - LeetCode (easy) 1742. Maximum Number of Balls in a Box https://leetcode.com/problems/maximum-number-of-balls-in-a-box/description/구현 문제였습니다.📕 풀이방법📔 입력 및 초기화각 limit로부터 얻은 ball 번호를 key로, 해당 번호의 개수를 value로 갖는 ballNumCountMap을 선언해줍니다. 📔 풀이과정1. low ~ high limit에 대해 for loop를 수행하며 각 ball 번호별 개수를 저장해줍니다.2. ballNumCountMap의 원소를 순회하며 가장 많이 나온 번호의 공 개수를 maxBalls에 저장해줍니다.📔 정답 출력 | 반환maxBalls를 반환합니다.📕 Code📔 C++class Solution {public: int getSum(int lim.. (SQL) - LeetCode (easy) 1741. Find Total Time Spent by Each Employee https://leetcode.com/problems/find-total-time-spent-by-each-employee/description/group by를 사용해본 문제였습니다.📕 풀이방법📔 풀이과정aggregation 함수 내에 수식이 들어갈 수 있습니다.employees table에서 event_day, emp_ud, out_time - in_time 의 합 을 event_day, emp_id에 대해 group화해 select해줍니다.* Oracle은 ''YYYY-MM-DD 00:00:00" 형식이므로 TO_CHAR로 정답에 맞게 total_time을 가공해줍니다.📕 Code📔 MySQLselect event_day as day, emp_id, sum(out_time - in_time).. (C++) - LeetCode (easy) 1736. Latest Time by Replacing Hidden Digits https://leetcode.com/problems/latest-time-by-replacing-hidden-digits/description/문자열을 다뤄보는 문제였습니다.📕 풀이방법📔 풀이과정각 time의 자리별 ?가 들어올 경우를 따져 적절한 숫자로 치환해줍니다.즉, xx:xx의 형식에서 x에 해당하는 부분의 index를 0,1,3,4일 때 '?'가 input으로 들어오므로 해당 경우를 확인해줍니다.1. time[0]이 '?'인 경우 1-1. 그 다음자리인 time[1]이 '4'이상이면서 ?가 아니라면 :왼편 문자열이 "?4" 또는 "?5" ...이므로 time[0]은 1이어야합니다. 1-2. 이외의 경우에는 :왼편 문자열이 "?0", "?1", "?2", "?3" 이 되므로 time[.. (C++) - LeetCode (easy) 1732. Find the Highest Altitude https://leetcode.com/problems/find-the-highest-altitude/description/📕 풀이방법📔 입력 및 초기화가장 높았던 고도 maxAltitude와 현 고도 curAltitude를 선언 후 0으로 각각 초기화해줍니다.📔 풀이과정gain의 원소를 순회하며 curAltitude를 갱신한 후 maxAltitude 중 최댓값을 구해 갱신해줍니다.📔 정답 출력 | 반환maxAltitude를 반환합니다.📕 Code📔 C++class Solution {public: int largestAltitude(vector& gain) { int maxAltitude = 0; int curAltitude = 0; for(auto g.. (SQL) - LeetCode (easy) 1731. The Number of Employees Which Report to Each Employee https://leetcode.com/problems/the-number-of-employees-which-report-to-each-employee/join을 사용해본 문제였습니다.📕 풀이방법📔 풀이과정employee_id가 reports_to인 조건으로 자기 자신을 join하면 필요한 employee_id별 보고된 행 개수를 구할 수 있습니다.해당 가상 table의 employee_id, name, employee_id의 개수, 보고자의 나이 평균을 select해준 후 employee_id에 대한 오름차순으로 정렬해줍니다.📕 Code📔 ANSI SQLselect e1.employee_id, e1.name, count(e1.employee_id) as reports_count, round(avg.. (SQL) - LeetCode (easy) 1729. Find Followers Count https://leetcode.com/problems/find-followers-count/description/group by를 사용해본 문제였습니다.📕 풀이방법📔 풀이과정user_id에 대해 group by한 후 user_id와 follwer_id의 countr값을 projection 후 select해줍니다.📕 Code📔 ANSI sqlselect user_id, count(follower_id) as followers_count from followersgroup by user_idorder by user_id*더 나은 내용을 위한 지적, 조언은 언제나 환영합니다. (C++) - LeetCode (easy) 1725. Number Of Rectangles That Can Form The Largest Square https://leetcode.com/problems/number-of-rectangles-that-can-form-the-largest-square/description/간단 구현문제였습니다.📕 풀이방법📔 입력 및 초기화각 직사각형의 최대길이를 저장할 vector lengths를 선언해줍니다.📔 풀이과정1. rectangles를 순회하며 각 직사각형의 length, width값 중 최솟값이 가질 수 있는 최대 직사각형의 한 변 길이이므로 그 값을 length에 저장해줍니다.2. lengths를 순회하며 각 직사각형이 가질 수 있는 한 변의 최댓값들 의 최댓값을 구해 largest에 저장합니다.3. largest와 같은 값을 가진 length를 구해 ans에 저장합니다.📔 정답 출력 | 반환ans.. (C++) - LeetCode (easy) 1716. Calculate Money in Leetcode Bank https://leetcode.com/problems/calculate-money-in-leetcode-bank/description/규칙대로 구현하는 문제였습니다.📕 풀이방법📔 입력 및 초기화일별 예금 금액 vector depositAmountPerDay를 선언 후 n + 1개의 방과 각 방을 0으로 초기화해줍니다.📔 풀이과정n만큼 원소를 순회하며 다음을 수행합니다.1. 현재 날이 7번째 날 초과면서 월요일이라면 저번주 월요일의 저금양 + 1만큼 예금합니다.2. 이외에 전날의 저금양 + 1만큼 예금합니다.3. deplositAmountPerDay의 원소를 순회하며 전체 저금양을 지역 변수 sum을 선언해 해당 원소값드를 누적해 저장합니다.📔 정답 출력 | 반환sum을 반환합니다.📕 Code📔.. 이전 1 ··· 45 46 47 48 49 50 51 ··· 293 다음