[LeetCode/Kotlin]344. Reverse String
·
LeetCode/Kotlin | Easy
344. Reverse String (Kotlin) 문제Write a function that reverses a string. The input string is given as an array of characters s.You must do this by modifying the input array in-place with O(1) extra memory.Example 1:Input: s = ["h","e","l","l","o"]Output: ["o","l","l","e","h"]Example 2:Input: s = ["H","a","n","n","a","h"]Output: ["h","a","n","n","a","H"]Constraints:1 s[i] is a printable ascii char..
[LeetCode/Kotlin]Easy - 13. Roman to Integer
·
LeetCode/Kotlin | Easy
Easy - 13. Roman to Integerhttps://leetcode.com/problems/roman-to-integer/description/나의 풀이풀이 접근 과정 우선 로마 숫자를 모두 배열에 넣고 치환하여 더하는 작업 진행 최종 풀이class Solution { fun romanToInt(s: String): Int { var input = s var answer = 0 val map: Array> = arrayOf( "CM" to 900, "CD" to 400, "XC" to 90, "XL" to 40, "IX" to 9, "..
[LeetCode/Kotlin]Easy - 278. First Bad Version
·
LeetCode/Kotlin | Easy
Easy - 278. First Bad Version 문제 해석 총 물건의 개수 n을 입력받는다. 그 중 불량품의 첫 시작을 찾아내는 문제이다. 만약 1~7번까지의 상품이 있는데, 3번이 불량인 경우 3번부터는 모두 불량품이 된다. 문제에서는 input이 n과 bad 두가지 값이라고 나오지만 n만 입력받는다 생각하고 풀면 된다. 풀이 방법 풀이 접근 과정 그냥 이진탐색으로 풀면 된다고 생각했다. 아예 예시에서 이진탐색으로 풀도록 알려줘서 접근 자체는 쉬웠다. 최종 소스코드 /* The isBadVersion API is defined in the parent class VersionControl. fun isBadVersion(version: Int) : Boolean {} */ class Solutio..
[LeetCode/Kotlin]Easy - 1. Two Sum
·
LeetCode/Kotlin | Easy
Two Sum - LeetCode Can you solve this real interview question? Two Sum - Given an array of integers nums and an integer target, return indices of the two numbers such that they add up to target. You may assume that each input would have exactly one solution, and you may not leetcode.com 문제 Given an array of integers nums and an integer target, return indices of the two numbers such that they add..
[LeetCode/Kotlin]Easy - 506. Relative Ranks
·
LeetCode/Kotlin | Easy
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 an integer array score of size n, where score[i] is the score of the ith athlete in a competition. All the scores are guaranteed to be unique. The athletes ar..
[LeetCode/Kotlin]Easy - 228. Summary Ranges
·
LeetCode/Kotlin | Easy
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 sorted unique integer array nums. A range [a,b] is the set of all integers from a to b (inclusive). Return the smallest sorted list of ranges that cover all..
[LeetCode/Kotlin]Easy - 704. Binary Search
·
LeetCode/Kotlin | Easy
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 문제 Given an array of integers nums which is sorted in ascending order, and an integer target, write a function to search target in nums. If target exists, then return its inde..
[LeetCode/Kotlin]Easy - 463. Island Perimeter
·
LeetCode/Kotlin | Easy
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 row x col grid representing a map where grid[i][j] = 1 represents land and grid[i][j] = 0 represents water. Grid cells are connected horizontally/vertically (..
[LeetCode/Kotlin]Easy - 345. Reverse Vowels of a String
·
LeetCode/Kotlin | Easy
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 문제 Given a string s, reverse only all the vowels in the string and return it. The vowels are 'a', 'e', 'i', 'o', and 'u', and they can appear in both lower and upper cases, mo..
[LeetCode/Kotlin]Easy - 441. Arranging Coins
·
LeetCode/Kotlin | Easy
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 have n coins and you want to build a staircase with these coins. The staircase consists of k rows where the ith row has exactly i coins. The last row of the staircase m..
[LeetCode/Kotlin]Easy - 141. Linked List Cycle
·
LeetCode/Kotlin | Easy
Linked List Cycle - LeetCode Can you solve this real interview question? Linked List Cycle - Given head, the head of a linked list, determine if the linked list has a cycle in it. There is a cycle in a linked list if there is some node in the list that can be reached again by continuo leetcode.com 문제 Given head, the head of a linked list, determine if the linked list has a cycle in it. There is ..
[LeetCode/Kotlin]Easy - 392. Is Subsequence
·
LeetCode/Kotlin | Easy
Is Subsequence - LeetCode Can you solve this real interview question? Is Subsequence - Given two strings s and t, return true if s is a subsequence of t, or false otherwise. A subsequence of a string is a new string that is formed from the original string by deleting some (can be n leetcode.com 문제 Given two strings s and t, return true if s is a subsequence of t, or false otherwise. A subsequenc..
[LeetCode/Kotlin]Easy - 58. Length of Last Word
·
LeetCode/Kotlin | Easy
Length of Last Word - LeetCode Can you solve this real interview question? Length of Last Word - Given a string s consisting of words and spaces, return the length of the last word in the string. A word is a maximal substring consisting of non-space characters only. Example 1: Input: leetcode.com 문제 Given a string s consisting of words and spaces, return the length of the last word in the string..
[LeetCode/Kotlin]Easy - 1356. Sort Integers by The Number of 1 Bits
·
LeetCode/Kotlin | Easy
Sort Integers by The Number of 1 Bits - LeetCode Can you solve this real interview question? Sort Integers by The Number of 1 Bits - You are given an integer array arr. Sort the integers in the array in ascending order by the number of 1's in their binary representation and in case of two or more integ leetcode.com 문제 You are given an integer array arr. Sort the integers in the array in ascendin..
[LeetCode/Kotlin]Easy - 28. Find the Index of the First Occurrence in a String
·
LeetCode/Kotlin | Easy
Find the Index of the First Occurrence in a String - LeetCode Can you solve this real interview question? Find the Index of the First Occurrence in a String - Given two strings needle and haystack, return the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack. Example 1: I leetcode.com 문제 Given two strings needle and haystack, return the index of the fir..
뿌꾸 빵
'LeetCode/Kotlin | Easy' 카테고리의 글 목록