전체 글(334)
-
[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 -
List extend
Algorithm문제를 풀다 보면, 어떤 동일한 값을 여러 번 list에 넣어야 하는 경우가 생긴다. 이때, [num] * frequency와 같이 적으면 된다. 예를들어, 1을 list에 3번 넣고 싶으면 list1.extend([1] * 3)이렇게 적으면 된다.
2024.07.23 -
python lambda 함수
lambda 함수는 간단한 statement 평가할 때 사용하기 좋다. algorithm에서 자주 쓰이니, 알아두도록 하자. lambda x : x + 3 ex ) lambda x , y : x + y lambda 뒤에 변수선언 : return값 선언
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