Algorithm(218)
-
[Leetcode]2191. Sort the Jumbled Numbers
1. 문제 :You are given a 0-indexed integer array mapping which represents the mapping rule of a shuffled decimal system. mapping[i] = j means digit i should be mapped to digit j in this system.The mapped value of an integer is the new integer obtained by replacing each occurrence of digit i in the integer with mapping[i] for all 0 2. 풀이 : 내가 풀었던 풀이 :class Solution: def sortJumbled(self, mappin..
2024.07.24 -
[Leetcode]1071. Greatest Common Divisor of Strings
1. 문제 : For two strings s and t, we say "t divides s" if and only if s = t + t + t + ... + t + t (i.e., t is concatenated with itself one or more times).Given two strings str1 and str2, return the largest string x such that x divides both str1 and str2. Example 1:Input: str1 = "ABCABC", str2 = "ABC"Output: "ABC"Example 2:Input: str1 = "ABABAB", str2 = "ABAB"Output: "AB"Example 3:Input: str1 = "L..
2024.07.24 -
[Leetcode]3211. Generate Binary Strings Without Adjacent Zeros
1. 문제 : You are given a positive integer n.A binary string x is valid if all substrings of x of length 2 contain at least one "1".Return all valid strings with length n, in any order. Example 1:Input: n = 3Output: ["010","011","101","110","111"]Explanation:The valid strings of length 3 are: "010", "011", "101", "110", and "111".Example 2:Input: n = 1Output: ["0","1"]Explanation:The valid strings..
2024.07.24 -
[Leetcode]53. Maximum Subarray
1. 문제 : Given an integer array nums, find the subarray with the largest sum, and return its sum. Example 1:Input: nums = [-2,1,-3,4,-1,2,1,-5,4]Output: 6Explanation: The subarray [4,-1,2,1] has the largest sum 6.Example 2:Input: nums = [1]Output: 1Explanation: The subarray [1] has the largest sum 1.Example 3:Input: nums = [5,4,-1,7,8]Output: 23Explanation: The subarray [5,4,-1,7,8] has the large..
2024.07.23 -
[Leetcode]342. Power of Four
1. 문제 : Given an integer n, return true if it is a power of four. Otherwise, return false.An integer n is a power of four, if there exists an integer x such that n == 4x. Example 1:Input: n = 16Output: trueExample 2:Input: n = 5Output: falseExample 3:Input: n = 1Output: true Constraints:-231 2. 풀이 : 첫 번째, while loop를 사용해서 4로 계속 나눈다. 나누다가 1이 되면 4의 거듭제곱인 거고 , 1보다 작다면 아닌 거다. # solution 1 class Sol..
2024.07.22 -
[Leetcode]203. Remove Linked List Elements
1. 문제 :Given the head of a linked list and an integer val, remove all the nodes of the linked list that has Node.val == val, and return the new head. Example 1:Input: head = [1,2,6,3,4,5,6], val = 6Output: [1,2,3,4,5]Example 2:Input: head = [], val = 1Output: []Example 3:Input: head = [7,7,7,7], val = 7Output: [] Constraints:The number of nodes in the list is in the range [0, 104].1 2. 풀이 : 첫 번..
2024.07.22