본문 바로가기

leetcode43

Python ] leetCode 1861 - Rotating the Box 리트코드 1861번 문제 You are given an m x n matrix of characters box representing a side-view of a box. Each cell of the box is one of the following: A stone '#'A stationary obstacle '*'Empty '.' The box is rotated 90 degrees clockwise, causing some of the stones to fall due to gravity. Each stone falls down until it lands on an obstacle, another stone, or the bottom of the box. Gravity does not affect.. 2024. 6. 2.
C++ ] leetCode 85 - Maximal Rectangle 리트코드 85번 문제 Given a rows x cols binary matrix filled with 0's and 1's, find the largest rectangle containing only 1's and return its area.   Example 1: Input: matrix = [["1","0","1","0","0"],["1","0","1","1","1"],["1","1","1","1","1"],["1","0","0","1","0"]]Output: 6Explanation: The maximal rectangle is shown in the above picture.  Example 2: Input: matrix = [["0"]]Output: 0  Example 3: Input: ma.. 2024. 5. 20.
C++ ] leetCode 84 - Largest Rectangle in Histogram 리트코드 84번 문제  Given an array of integers heights representing the histogram's bar height where the width of each bar is 1, return the area of the largest rectangle in the histogram.  Example 1:Input: heights = [2,1,5,6,2,3]Output: 10Explanation: The above is a histogram where width of each bar is 1. The largest rectangle is shown in the red area, which has an area = 10 units.  Example 2:Input: he.. 2024. 5. 18.
C++ ] leetCode 42 - Trapping Rain Water 리트코드 42번 문제 Given n non-negative integers representing an elevation map where the width of each bar is 1, compute how much water it can trap after raining. Example 1: Input: height = [0,1,0,2,1,0,1,3,2,1,2,1] Output: 6 Explanation: The above elevation map (black section) is represented by array [0,1,0,2,1,0,1,3,2,1,2,1]. In this case, 6 units of rain water (blue section) are being trapped. Examp.. 2024. 5. 14.
C++ ] leetCode 937 - Reorder Data in Log Files 리트코드 937번 문제 You are given an array of logs. Each log is a space-delimited string of words, where the first word is the identifier. There are two types of logs: Letter-logs: All words (except the identifier) consist of lowercase English letters. Digit-logs: All words (except the identifier) consist of digits. Reorder these logs so that: The letter-logs come before all digit-logs. The letter-logs.. 2024. 5. 10.
C++ ] leetCode 143 - Reorder List 리트코드 143번 문제 You are given the head of a singly linked-list. The list can be represented as: L0 → L1 → … → Ln - 1 → Ln Reorder the list to be on the following form: L0 → Ln → L1 → Ln - 1 → L2 → Ln - 2 → … You may not modify the values in the list's nodes. Only nodes themselves may be changed. Example 1: Input: head = [1,2,3,4] Output: [1,4,2,3] Example 2: Input: head = [1,2,3,4,5] Output: [1,5,2.. 2024. 5. 8.
C++ ] leetCode 1195 - Fizz Buzz Multithreaded 리트코드 1195번 문제 You have the four functions: printFizz that prints the word "fizz" to the console, printBuzz that prints the word "buzz" to the console, printFizzBuzz that prints the word "fizzbuzz" to the console, and printNumber that prints a given integer to the console. You are given an instance of the class FizzBuzz that has four functions: fizz, buzz, fizzbuzz and number. The same instance o.. 2024. 5. 6.
C++ ] leetCode 784 - Letter Case Permutation Given a string s, you can transform every letter individually to be lowercase or uppercase to create another string. Return a list of all possible strings we could create. Return the output in any order. Example 1: Input: s = "a1b2" Output: ["a1b2","a1B2","A1b2","A1B2"] Example 2: Input: s = "3z4" Output: ["3z4","3Z4"] Constraints: 1 2024. 4. 30.
C++ ] leetCode 1010 - Pairs of Songs With Total Durations Divisible by 60 리트코드 1010 문제 You are given a list of songs where the ith song has a duration of time[i] seconds. Return the number of pairs of songs for which their total duration in seconds is divisible by 60. Formally, we want the number of indices i, j such that i < j with (time[i] + time[j]) % 60 == 0. Example 1: Input: time = [30,20,150,100,40] Output: 3 Explanation: Three pairs have a total duration divis.. 2024. 4. 24.
C++ ] leetCode 1029 - Two City Scheduling 리트코드 1029 문제 A company is planning to interview 2n people. Given the array costs where costs[i] = [aCosti, bCosti], the cost of flying the ith person to city a is aCosti, and the cost of flying the ith person to city b is bCosti. Return the minimum cost to fly every person to a city such that exactly n people arrive in each city. Example 1: Input: costs = [[10,20],[30,200],[400,50],[30,20]] Outp.. 2024. 4. 21.
C++ ] leetCode 1418 - Display Table of Food Orders in a Restaurant 리트코드 1418 문제 Given the array orders, which represents the orders that customers have done in a restaurant. More specifically orders[i]=[customerNamei,tableNumberi,foodItemi] where customerNamei is the name of the customer, tableNumberi is the table customer sit at, and foodItemi is the item customer orders. Return the restaurant's “display table”. The “display table” is a table whose row entries.. 2024. 4. 20.
C] leetCode 2540 - Minimum Common Value (+ Two Pointers) 리트코드 2540 문제 Given two integer arrays nums1 and nums2, sorted in non-decreasing order, return the minimum integer common to both arrays. If there is no common integer amongst nums1 and nums2, return -1. Note that an integer is said to be common to nums1 and nums2 if both arrays have at least one occurrence of that integer. Example 1: Input: nums1 = [1,2,3], nums2 = [2,4] Output: 2 Explanation: T.. 2024. 4. 18.
C++ ] leetCode 3005 - Count Elements With Maximum Frequency 리트코드 3005 문제 You are given an array nums consisting of positive integers. Return the total frequencies of elements in nums such that those elements all have the maximum frequency. The frequency of an element is the number of occurrences of that element in the array. Example 1: Input: nums = [1,2,2,3,1,4] Output: 4 Explanation: The elements 1 and 2 have a frequency of 2 which is the maximum frequ.. 2024. 4. 16.
C++ ] leetCode 1396 - Design Underground System 리트코드 1396번 문제 An underground railway system is keeping track of customer travel times between different stations. They are using this data to calculate the average time it takes to travel from one station to another. Implement the UndergroundSystem class: void checkIn(int id, string stationName, int t) A customer with a card ID equal to id, checks in at the station stationName at time t. A custo.. 2024. 4. 14.
C++ ] leetCode 1249 - Minimum Remove to Make Valid Parentheses 리트코드 1249번 문제 Given a string s of '(' , ')' and lowercase English characters. Your task is to remove the minimum number of parentheses ( '(' or ')', in any positions ) so that the resulting parentheses string is valid and return any valid string. Formally, a parentheses string is valid if and only if: It is the empty string, contains only lowercase characters, or It can be written as AB (A conca.. 2024. 4. 9.
C++ ] leetCode 861 - Score After Flipping Matrix 리트코드 861 문제 You are given an m x n binary matrix grid. A move consists of choosing any row or column and toggling each value in that row or column (i.e., changing all 0's to 1's, and all 1's to 0's). Every row of the matrix is interpreted as a binary number, and the score of the matrix is the sum of these numbers. Return the highest possible score after making any number of moves (including zero.. 2024. 4. 6.
C++ ] leetCode 2596 - Check Knight Tour Configuration 리트코드 2596번 문제 There is a knight on an n x n chessboard. In a valid configuration, the knight starts at the top-left cell of the board and visits every cell on the board exactly once. You are given an n x n integer matrix grid consisting of distinct integers from the range [0, n * n - 1] where grid[row][col] indicates that the cell (row, col) is the grid[row][col]th cell that the knight visited. .. 2024. 4. 2.
C++ ] leetCode 150 - Evaluate Reverse Polish Notation You are given an array of strings tokens that represents an arithmetic expression in a Reverse Polish Notation. Evaluate the expression. Return an integer that represents the value of the expression. Note that: The valid operators are '+', '-', '*', and '/'. Each operand may be an integer or another expression. The division between two integers always truncates toward zero. There will not be any.. 2024. 3. 27.
C++ ] leetCode 739 - Daily Temperatures 리트코드 739번 문제 Given an array of integers temperatures represents the daily temperatures, return an array answer such that answer[i] is the number of days you have to wait after the ith day to get a warmer temperature. If there is no future day for which this is possible, keep answer[i] == 0 instead. Example 1: Input: temperatures = [73,74,75,71,69,72,76,73] Output: [1,1,4,2,1,1,0,0] Example 2: In.. 2024. 3. 22.
C++ ] leetCode 2136 - Earliest Possible Day of Full Bloom 리트코드 2136 문제 You have n flower seeds. Every seed must be planted first before it can begin to grow, then bloom. Planting a seed takes time and so does the growth of a seed. You are given two 0-indexed integer arrays plantTime and growTime, of length n each: plantTime[i] is the number of full days it takes you to plant the ith seed. Every day, you can work on planting exactly one seed. You do not.. 2024. 3. 18.
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.