Coding Test
-
[LeetCode] 1672. Richest Customer Wealth c++Coding Test/LeetCode 2022. 10. 10. 16:43
문제 You are given an m x n integer grid accounts where accounts[i][j] is the amount of money the ith customer has in the jth bank. Return the wealth that the richest customer has. A customer's wealth is the amount of money they have in all their bank accounts. The richest customer is the customer that has the maximum wealth. Input: accounts = [[1,2,3],[3,2,1]] Output..
-
[LeetCode] 1470. Shuffle the Array c+Coding Test/LeetCode 2022. 10. 10. 16:31
문제 Given the array nums consisting of 2n elements in the form [x1,x2,...,xn,y1,y2,...,yn]. Return the array in the form [x1,y1,x2,y2,...,xn,yn]. Input: nums = [2,5,1,3,4,7], n = 3 Output: [2,3,5,4,1,7] Explanation: Since x1=2, x2=5, x3=1, y1=3, y2=4, y3=7 then the answer is [2,3,5,4,1,7]. 문제 해결 class Solution { public: vector shuffle(vector& nums, int n) { vector answer; for(int i = 0; i < n; i+..
-
[LeetCode] 2011. Final Value of Variable After Performing Operations c++Coding Test/LeetCode 2022. 10. 10. 16:06
문제 There is a programming language with only four operations and one variable X: ++X and X++ increments the value of the variable X by 1. --X and X-- decrements the value of the variable X by 1. Initially, the value of X is 0. Given an array of strings operations containing a list of operations, return the final value of X after performing all the operations. Input: operations = ["--X","X++","X+..
-
[LeetCode] 35. Search Insert Position c++Coding Test/LeetCode 2022. 10. 10. 13:41
문제 Given a sorted array of distinct integers and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in order. You must write an algorithm with O(log n) runtime complexity. Input: nums = [1,3,5,6], target = 5 Output: 2 배열 원소 중 target과 같은 값이 있다면 해당 index 구하고, 없다면 오름차순인 배열에 위치시킬 index를 구하는 문제이다. 문제 해결 이 문제를 해결하기 위해 lower_bound 함수에..
-
[LeetCode] 1480. Running Sum of 1d Array c++Coding Test/LeetCode 2022. 10. 10. 13:20
문제 Given an array nums. We define a running sum of an array as runningSum[i] = sum(nums[0]…nums[i]). Return the running sum of nums. Input: nums = [1,2,3,4] Output: [1,3,6,10] Explanation: Running sum is obtained as follows: [1, 1+2, 1+2+3, 1+2+3+4]. 문제 해결 class Solution { public: vector runningSum(vector& nums) { int len = nums.size(); vector answer(len, 0); answer[0] = nums[0]; for(int i = 1; ..
-
[프로그래머스] 빛의 경로 사이클 c++Coding Test/programmers 2022. 10. 4. 11:44
문제 설명 S, L , R 방향이 주어진다. S는 직진, L 은 좌회전, R은 우회전 한다. (빛이 들어온 방향 기준) 기존에 방문한 좌표를 같은 방향으로 재방문한 경우 "싸이클"이 형성된다. ※사이클 : 같은 좌표, 같은 방향 으로 재방문 빛이 격자의 끝을 넘어갈 경우, 반대쪽 끝으로 다시 돌아옵니다. 예를 들어, 빛이 1행에서 행이 줄어드는 방향으로 이동할 경우, 같은 열의 반대쪽 끝 행으로 다시 돌아옵니다. 사이클을 찾고, 각 사이클의 길이를 구하는 문제이다. 제한 사항 1 ≤ grid의 길이 ≤ 500 1 ≤ grid의 각 문자열의 길이 ≤ 500 grid의 모든 문자열의 길이는 서로 같습니다. grid의 모든 문자열은 'L', 'R', 'S'로 이루어져 있습니다. 입출력 예 grid result..