Python 106

[LeetCode] 3178. Find the Child Who Has the Ball After K Seconds

3178. Find the Child Who Has the Ball After K SecondsLeetCodehttps://leetcode.com/problems/find-the-child-who-has-the-ball-after-k-seconds/문제두 개의 양의 정수 n과 k가 주어졌습니다.0부터 n-1까지 번호가 매겨진 n명의 아이가 왼쪽에서 오른쪽으로 줄을 서 있습니다.처음에는 0번 아이가 공을 갖고 있으며 매초 공을 오른쪽으로 전달합니다.공이 줄의 양 끝에 도달하면 전달 방향이 반대로 바뀝니다.k초 후에 공을 받은 아이의 번호를 반환하는 코드를 작성하세요.예제Input: n = 3, k = 5Output: 1풀이 과정 #1변수 i를 0부터 n-1까지 1씩 증가시키며 i를 리스트로 생성하여 변수 ..

[LeetCode] 3280. Convert Date to Binary

3280. Convert Date to BinaryLeetCodehttps://leetcode.com/problems/convert-date-to-binary/문제문자열 date가 주어졌습니다.date는 yyyy-mm-dd 형식으로 그레고리력 날짜를 나타냅니다.연도, 월, 일을 각각 2진수로 변환한 후 year-month-date 형식으로 결합한 문자열을 반환하는 코드를 작성하세요.예제Input: date = "2080-02-29"Output: "100000100000-10-11101"풀이 과정 #1주어진 문자열 date를 "-" 기준으로 분리하여 변수 l_date에 저장합니다.빈 리스트 bin_date를 생성합니다.l_date의 모든 요소를 순회하며 현재 요소(num)를 정수로 변환한 후 2진수로 변환..

[LeetCode] 1800. Maximum Ascending Subarray Sum

1800. Maximum Ascending Subarray SumLeetCodehttps://leetcode.com/problems/maximum-ascending-subarray-sum/문제양의 정수 배열 nums가 주어졌습니다.부분 배열은 nums 내의 연속된 요소를 의미하며 길이가 1인 배열도 오름차순 부분 배열로 간주합니다.오름차순으로 정렬된 부분 배열의 요소 합 중 최댓값을 반환하는 코드를 작성하세요. 예제Input: nums = [10, 20, 30, 5, 10, 50]Output: 65풀이 과정주어진 양의 정수 배열 nums의 첫 번째 요소를 변수 answer와 sum_에 각각 저장합니다.인덱스 i를 사용하여 nums의 두 번째 요소부터 순회하며 다음 조건을 수행합니다.현재 요소(nums[i..

[LeetCode] 2119. A Number After a Double Reversal

2119. A Number After a Double ReversalLeetCodehttps://leetcode.com/problems/a-number-after-a-double-reversal/문제정수 num이 주어졌습니다.num을 뒤집어 정수 reversed1을 만들고 다시 reversed1을 뒤집어 정수 reversed2를 만듭니다.reversed2가 num과 같으면 True, 그렇지 않으면 False를 반환하는 코드를 작성하세요.예제Input: num = 526Output: True풀이 과정주어진 정수 num을 문자열로 변환해 순서를 뒤집은 후 다시 정수로 변환하여 변수 reversed1에 저장합니다.reversed1을 문자열로 변환해 순서를 뒤집은 후 다시 정수로 변환하여 변수 reversed2..

Python - Algorithm #49

Python AlgorithmLeetCode2119. A Number After a Double ReversalReversing an integer means to reverse all its digits.For example, reversing 2021 gives 1202. Reversing 12300 gives 321 as the leading zeros are not retained.Given an integer num, reverse num to get reversed1, then reverse reversed1 to get reversed2. Return true if reversed2 equals num. Otherwise return false.Constraints0 ≤ num ≤ 10⁶cl..

[LeetCode] 1309. Decrypt String from Alphabet to Integer Mapping

1309. Decrypt String from Alphabet to Integer MappingLeetCodehttps://leetcode.com/problems/decrypt-string-from-alphabet-to-integer-mapping/문제문자열 s가 주어졌습니다.s는 숫자와 "#"으로 이루어져 있으며 문자 "a"부터 "i"는 각각 "1"에서 "9"로 표현되고, 문자 "j"부터 "z"는 각각 "10#"에서 "26#"로 표현됩니다.s를 영어 소문자로 매핑한 문자열을 반환하는 코드를 작성하세요. 예제Input: s = "10#11#12"Output: "jkab"풀이 과정빈 문자열 answer를 생성합니다.인덱스를 나타내는 변수 i를 0으로 초기화합니다.인덱스 i를 사용하여 s의 모든 문자를 순회..

[LeetCode] 2586. Count the Number of Vowel Strings in Range

2586. Count the Number of Vowel Strings in Rangehttps://leetcode.com/problems/count-the-number-of-vowel-strings-in-range/문제배열 words와 두 개의 정수 left, right가 주어졌습니다.모음으로 시작해서 모음으로 끝나는 문자열을 vowel string이라고 하며 모음은 "a", "e", "i", "o", "u"입니다. left와 right 사이의 범위에 속하는 i에 대해 words[i]가 vowel string인 문자열의 개수를 반환하는 코드를 작성하세요. 예제Input: words = ["are", "amy", "u"], left = 0, right = 2Output: 2풀이 과정변수 answer를 0..