목록코딩테스트 & 자료구조 (2)
티라미수 코딩생활

문제 Write a function to find the longest common prefix string amongst an array of strings. If there is no common prefix, return an empty string "". Input: strs = ["flower","flow","flight"] Output: "fl" class Solution { fun longestCommonPrefix(strs: Array): String { } } 처음에 prefix 라는 단어를 놓쳐서 문제를 보자마자 기겁했었습니다. 전 배열에 공통적으로 포함되어 있는 (자리가 상관없는) String 중 가장 긴 거 찾기 인 줄 알았습니다.. 다행히 시작 위치는 앞에서부터 고정입니다. 나의 ..
풀이 언어 : Java, Kotlin 내가 푼 시간복잡도 : O(n^2) -> O(n) 문제 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 use the same element twice. You can return the answer in any order. 처음으로 풀어본 LeetCode 문제 문제를 봤을 때, 이중 for 문을 사용하면 금방 해결할 수 있어 보였지만, 시간복잡도 O(n^2)..