본문 바로가기

자료구조,알고리즘

(51)
LeetCode-148 Sort List 파이썬 풀이 Sort List - LeetCode Can you solve this real interview question? Sort List - Given the head of a linked list, return the list after sorting it in ascending order. Example 1: [https://assets.leetcode.com/uploads/2020/09/14/sort_list_1.jpg] Input: head = [4,2,1,3] Output: [1, leetcode.com 문제 linkedlist를 시간복잡도o(nlogn)과 공간복잡도 o(1)을 만족하여 정렬하는 문제입니다. 퀵 정렬은 시간 복잡도에서 o(nlogn)을 뛰어 넘을 수 있기 때문에 o(nlogn)의 시..
LeetCode-128 Longest Consecutive Sequence 파이썬 풀이 Longest Consecutive Sequence - LeetCode Can you solve this real interview question? Longest Consecutive Sequence - Given an unsorted array of integers nums, return the length of the longest consecutive elements sequence. You must write an algorithm that runs in O(n) time. Example 1: Input: leetcode.com 문제 주어진 int형 배열안에서 가장 길게 지속되는 숫자들의 길이를 반환하면 됩니다. 1,2,3,4 이런식으로 지속되는 경우를 찾는 것이고 중간에 중복 값이 들어있어서는..
LeetCode-290 Word Pattern 파이썬 풀이 Word Pattern - LeetCode Can you solve this real interview question? Word Pattern - Given a pattern and a string s, find if s follows the same pattern. Here follow means a full match, such that there is a bijection between a letter in pattern and a non-empty word in s. Example leetcode.com 문제 pattern과 s의 구조가 같은지 판별하는 문제입니다. 문자열 pattern이 반복되는 구조가 s에서 단어가 반복되는 구조와 같은지 판별하면 됩니다. 풀이 1. 이전 게시글에서 풀었던 것..
LeetCode-49 Group Anagrams 파이썬 풀이 Group Anagrams - LeetCode Can you solve this real interview question? Group Anagrams - Given an array of strings strs, group the anagrams together. You can return the answer in any order. An Anagram is a word or phrase formed by rearranging the letters of a different word or phrase leetcode.com 문제 strs배열 안에 있는 문자열들을 같은 애너그램 끼리 묶어 반환하는 문제입니다. 애너그램은 글자의 순서만 다를뿐 같은 문자인 경우를 애너그램이라고 합니다. 풀이 1. strs를 ..
LeetCode-202 Happy Number 파이썬 풀이 Happy Number - LeetCode Can you solve this real interview question? Happy Number - Write an algorithm to determine if a number n is happy. A happy number is a number defined by the following process: * Starting with any positive integer, replace the number by the sum of the squar leetcode.com 문제 주어진 숫자 n이 Happy Number인지 판별하는 문제입니다. HappyNumber는 n의 각 자리수를 제곱하여 더한 값을 다시 n으로 보고 각 자리수를 제곱하여 더하고를 반복하..
LeetCode-150 Evaluate Reverse Polish Notation 파이썬 문제 풀이 Evaluate Reverse Polish Notation - LeetCode Can you solve this real interview question? Evaluate Reverse Polish Notation - You are given an array of strings tokens that represents an arithmetic expression in a Reverse Polish Notation [http://en.wikipedia.org/wiki/Reverse_Polish_notation]. Evaluate t leetcode.com 문제 역폴란드 표기법으로 작성된 계산식을 푸는 문제입니다. 배열 안에 숫자와 연산자가 입력되어있고, 역폴란드 표기법에 맞게 계산하면 됩니다. 풀이 역폴..
LeetCode-205 Isomorphic Strings 파이썬 풀이 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 문제 두 문자열 s와 t가 구조적으로 같은지를 판별하는 문제입니다. 예를 들어 egg는 122, add는 122이기에 동일한 구조 입니다. 하지만 foo는 122, bar는 123으로 다른 구조를 가집니다. 각 숫자는 해당 문자가 어떤 위치에서 몇번 나타났는 지를 식별하기 위해 사용하는 것입니다. 풀이 1. s와..
LeetCode-383 Ransom Note 파이썬 풀이 Ransom Note - LeetCode Can you solve this real interview question? Ransom Note - Given two strings ransomNote and magazine, return true if ransomNote can be constructed by using the letters from magazine and false otherwise. Each letter in magazine can only be used once in ranso leetcode.com 문제 문자열 magazine에 있는 문자들을 조합하여 ransomeNote 문자열을 만들 수 있는지 판별하는 문제입니다. magazine에 있는 문자들을 중복해서 사용할 수는 없습니다. 풀..