본문 바로가기

코딩테스트54

C++ ] leetCode 6 - Zigzag Conversion leetCode 6번 문제 The string "PAYPALISHIRING" is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility)And then read line by line: "PAHNAPLSIIGYIR"Write the code that will take a string and make this conversion given a number of rows: string convert(string s, int numRows);  Example 1: Input: s = "PAYPALISHIRING",.. 2024. 3. 14.
C++] leetCode 1 - Two Sum 리트코드 1번 문제 Given an array of integers nums and an integer target, return indices of the two numbers such that they add up to target. You may assume that each input would have exactly one solution, and you may not use the same element twice. You can return the answer in any order. Example 1: Input: nums = [2,7,11,15], target = 9 Output: [0,1] Explanation: Because nums[0] + nums[1] == 9, we return.. 2024. 3. 13.
C++ ] leetCode 2120 - Execution of All Suffix Instructions Staying in a Grid 리트코드 2120 문제 There is an n x n grid, with the top-left cell at (0, 0) and the bottom-right cell at (n - 1, n - 1). You are given the integer n and an integer array startPos where startPos = [startrow, startcol] indicates that a robot is initially at cell (startrow, startcol). You are also given a 0-indexed string s of length m where s[i] is the ith instruction for the robot: 'L' (move left), 'R'.. 2024. 3. 12.
C++ ] leetCode 2161 - Partition Array According to Given Pivot 리트코드 2161 문제 You are given a 0-indexed integer array nums and an integer pivot. Rearrange nums such that the following conditions are satisfied: Every element less than pivot appears before every element greater than pivot. Every element equal to pivot appears in between the elements less than and greater than pivot. The relative order of the elements less than pivot and the elements greater tha.. 2024. 3. 8.
C++ ] leetCode 2482 - Difference Between Ones and Zeros in Row and Column 리트코드 2482 문제 You are given a 0-indexed m x n binary matrix grid. A 0-indexed m x n difference matrix diff is created with the following procedure: Let the number of ones in the ith row be onesRowi. Let the number of ones in the jth column be onesColj. Let the number of zeros in the ith row be zerosRowi. Let the number of zeros in the jth column be zerosColj. diff[i][j] = onesRowi + onesColj - ze.. 2024. 3. 6.
C++ ] leetCode 2545 - Sort the Students by Their Kth Score 리트코드 2545 문제 There is a class with m students and n exams. You are given a 0-indexed m x n integer matrix score, where each row represents one student and score[i][j] denotes the score the ith student got in the jth exam. The matrix score contains distinct integers only. You are also given an integer k. Sort the students (i.e., the rows of the matrix) by their scores in the kth (0-indexed) exam .. 2024. 3. 4.
C ] leetCode 2125 - Number of Laser Beams in a Bank 리트코드 2125 문제 Anti-theft security devices are activated inside a bank. You are given a 0-indexed binary string array bank representing the floor plan of the bank, which is an m x n 2D matrix. bank[i] represents the ith row, consisting of '0's and '1's. '0' means the cell is empty, while'1' means the cell has a security device. There is one laser beam between any two security devices if both condi.. 2024. 3. 2.
C++ ] leetCode 1630 - Arithmetic Subarrays 리트코드 1630 문제 A sequence of numbers is called arithmetic if it consists of at least two elements, and the difference between every two consecutive elements is the same. More formally, a sequence s is arithmetic if and only if s[i+1] - s[i] == s[1] - s[0] for all valid i.   For example, these are arithmetic sequences: 1, 3, 5, 7, 9 7, 7, 7, 7 3, -1, -5, -9  The following sequence is not arithmetic.. 2024. 2. 28.
C ] leetCode 1561 - Maximum Number of Coins You Can Get 리트코드 1561 문제 There are 3n piles of coins of varying size, you and your friends will take piles of coins as follows: In each step, you will choose any 3 piles of coins (not necessarily consecutive). Of your choice, Alice will pick the pile with the maximum number of coins. You will pick the next pile with the maximum number of coins. Your friend Bob will pick the last pile. Repeat until there are.. 2024. 2. 26.
C++ ] leetCode 36 - Valid Sudoku 리트코드 36 문제 Determine if a 9 x 9 Sudoku board is valid. Only the filled cells need to be validated according to the following rules: Each row must contain the digits 1-9 without repetition. Each column must contain the digits 1-9 without repetition. Each of the nine 3 x 3 sub-boxes of the grid must contain the digits 1-9 without repetition. Note: A Sudoku board (partially filled) could be valid b.. 2024. 2. 22.