[LeetCode/Kotlin]Medium - 5. Longest Palindromic Substring
·
LeetCode/Kotlin | Medium
문제 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) { ..
[LeetCode/Kotlin]Medium - 34. Find First and Last Position of Element in Sorted Array
·
LeetCode/Kotlin | Medium
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..
[LeetCode]Medium - 238. Product of Array Except Self
·
LeetCode/Kotlin | Medium
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..
[LeetCode/Kotlin]442. Find All Duplicates in an Array
·
LeetCode/Kotlin | Medium
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..
[LeetCode/Kotlin]Medium - 6. Zigzag Conversation
·
LeetCode/Kotlin | Medium
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: ..
[LeetCode/Kotlin]Medium - 12. Integer to Roman
·
LeetCode/Kotlin | Medium
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..
[LeetCode/Kotlin]Medium - 396. Rotate Function
·
LeetCode/Kotlin | Medium
Rotate Function - LeetCode Can you solve this real interview question? Rotate Function - You are given an integer array nums of length n. Assume arrk to be an array obtained by rotating nums by k positions clock-wise. We define the rotation function F on nums as follow: * F(k) = 0 * leetcode.com 문제 You are given an integer array nums of length n. Assume arrk to be an array obtained by rotating n..
[LeetCode/Kotlin]Medium - 2807. Insert Greatest Common Divisors in Linked List
·
LeetCode/Kotlin | Medium
Insert Greatest Common Divisors in Linked List - LeetCode Can you solve this real interview question? Insert Greatest Common Divisors in Linked List - Given the head of a linked list head, in which each node contains an integer value. Between every pair of adjacent nodes, insert a new node with a value equal to t leetcode.com 문제 Given the head of a linked list head, in which each node contains a..
[LeetCode/Kotlin]Medium - 322. Coin Change
·
LeetCode/Kotlin | Medium
Coin Change - LeetCode Can you solve this real interview question? Coin Change - You are given an integer array coins representing coins of different denominations and an integer amount representing a total amount of money. Return the fewest number of coins that you need to make leetcode.com 문제 You are given an integer array coins representing coins of different denominations and an integer amou..
[LeetCode/Kotlin]Medium - 2690. Happy Students
·
LeetCode/Kotlin | Medium
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 문제 You are given a 0-indexed integer array nums of length n where n is the total number of students in the class. The class teacher tries to select a group of students so that..
[LeetCode/Kotlin]Medium - 39. Combination Sum
·
LeetCode/Kotlin | Medium
Combination Sum - LeetCode Can you solve this real interview question? Combination Sum - Given an array of distinct integers candidates and a target integer target, return a list of all unique combinations of candidates where the chosen numbers sum to target. You may return the comb leetcode.com 문제 Given an array of distinct integers candidates and a target integer target, return a list of all u..
[LeetCode/Kotlin]Medium - 1343. Number of Sub-arrays of Size K and Average Greater than or Equal to Threshold
·
LeetCode/Kotlin | Medium
Number of Sub-arrays of Size K and Average Greater than or Equal to Threshold - LeetCode Can you solve this real interview question? Number of Sub-arrays of Size K and Average Greater than or Equal to Threshold - Given an array of integers arr and two integers k and threshold, return the number of sub-arrays of size k and average greater than leetcode.com 문제 Given an array of integers arr and tw..
[LeetCode/Kotlin]Medium - 518. Coin Change II
·
LeetCode/Kotlin | Medium
Coin Change II - LeetCode Can you solve this real interview question? Coin Change II - You are given an integer array coins representing coins of different denominations and an integer amount representing a total amount of money. Return the number of combinations that make up that leetcode.com 문제 You are given an integer array coins representing coins of different denominations and an integer am..
[LeetCode/Kotlin]Medium - 36. Valid Sudoku
·
LeetCode/Kotlin | Medium
Valid Sudoku - LeetCode Can you solve this real interview question? Valid Sudoku - Determine if a 9 x 9 Sudoku board is valid. Only the filled cells need to be validated according to the following rules: 1. Each row must contain the digits 1-9 without repetition. 2. Each c leetcode.com 문제 Determine if a 9 x 9 Sudoku board is valid. Only the filled cells need to be validated according to the foll..
[LeetCode/Kotlin]Medium - 53. Maximum Subarray
·
LeetCode/Kotlin | Medium
Maximum Subarray - LeetCode Can you solve this real interview question? Maximum Subarray - 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: 6 Explanation: The subarray [4,-1,2,1] has t leetcode.com 문제 Given an integer array nums, find the subarray with the largest sum, and return its sum. Example 1: ..
뿌꾸 빵
'LeetCode/Kotlin | Medium' 카테고리의 글 목록