LeetCode/Kotlin | Medium(20)
-
[LeetCode/Kotlin]Medium - 5. Longest Palindromic Substring
문제 url: https://leetcode.com/problems/longest-palindromic-substring/ 문제 해석s라는 문자열을 입력받을 때, 해당 문자열 내에서 앞뒤로 봐도 똑같은 글자들 중 가장 긴 글자를 찾아내면 된다.풀이 방법풀이 접근 과정기존에 프로그래머스 Level3 문제에서 가장 긴 팰린드롬 문제를 풀었던 적이 있다.그 풀이와 유사하게 풀었다.최종 소스코드class Solution { fun longestPalindrome(s: String): String { var cnt = 0 var answerIdx = Pair(0,0) fun palindrom(startIndex: Int, endIndex: Int) { ..
2024.06.04 -
[LeetCode/Kotlin]Medium - 34. Find First and Last Position of Element in Sorted Array
Medium - 34. Find First and Last Position of Element in Sorted Array https://leetcode.com/problems/find-first-and-last-position-of-element-in-sorted-array/나의 풀이class Solution { fun searchRange(nums: IntArray, target: Int): IntArray { var answer = intArrayOf(-1, -1) var start = 0 var end = nums.lastIndex var mid: Int while (start = 0 && nums[mid-index] == tar..
2024.05.09 -
[LeetCode]Medium - 238. Product of Array Except Self
Medium - 238. Product of Array Except Self https://leetcode.com/problems/product-of-array-except-self/description/ 문제 해석 반복문을 한번만 돌려 나를 제외한 모든 값들의 곱을 구해야 한다. 대신! 나누기 연산을 사용하지 않을 것! 풀이 방법 풀이 접근 과정 인터넷 힌트 참고함. 자신을 기준으로 왼쪽값들의 곱을 구하고 자신을 기준으로 오른쪽값들의 곱을 구해 그 곱을 다시 곱하면 된다. 최종 소스코드 class Solution { fun productExceptSelf(nums: IntArray): IntArray { val answer = IntArray(nums.size) { 1 } for (i in 1 unti..
2024.03.21 -
[LeetCode/Kotlin]442. Find All Duplicates in an Array
LeetCode - The World's Leading Online Programming Learning Platform Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com 문제 해석 배열 안에서 중복된 값만 뽑아내야 한다. 하지만 조건에 O(N)을 사용하라고 하였으므로 반복문은 한번만 돌아야 함. 그리고 추가 공간만 사용해야 한다는 사실을 명심하자 !! 풀이 방법 풀이 접근 과정 반복문을 한 번만 돌기 위해 map을 사용하여 중복된 값을 걸러내고자 하였다. 최종 소스코드 class..
2024.02.14 -
[LeetCode/Kotlin]Medium - 6. Zigzag Conversation
Zigzag Conversion - LeetCode Can you solve this real interview question? Zigzag Conversion - 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) P A H N A P L S I I leetcode.com 문제 The string "PAYPALISHIRING" is written in a zigzag pattern on a given number of rows like this: ..
2023.11.02 -
[LeetCode/Kotlin]Medium - 12. Integer to Roman
Integer to Roman - LeetCode Can you solve this real interview question? Integer to Roman - Roman numerals are represented by seven different symbols: I, V, X, L, C, D and M. Symbol Value I 1 V 5 X 10 L 50 C 100 D 500 M 1000 For example, 2 is written as II in Roman numeral, just tw leetcode.com 문제 Roman numerals are represented by seven different symbols: I, V, X, L, C, D and M. SymbolValue I 1 V..
2023.11.02