Algorithm 25

[Leetcode 332] 여정 재구성 - DFS, 우선순위 큐

https://leetcode.com/problems/reconstruct-itinerary/description/ Reconstruct Itinerary - LeetCode Can you solve this real interview question? Reconstruct Itinerary - You are given a list of airline tickets where tickets[i] = [fromi, toi] represent the departure and the arrival airports of one flight. Reconstruct the itinerary in order and return it. Al leetcode.com Problems 티켓[i] = [출발지, 도착지]가 한..

Algorithm/Leetcode 2024.03.06

[Leetcode 347] Top K Frequent Elements - 해시테이블, 우선순위큐

https://leetcode.com/problems/top-k-frequent-elements/ 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 Problems 빈도순으로 k개의 엘리먼트를 추출하라. O(nlogn)보다 더 빠른 시간복잡도로 구현해라. 입력: nums = [1, 1, 1, 2, 2, 3, 4], k = 2 출력: [1, 2] 설명: 1이 총 ..

Algorithm/Leetcode 2024.02.13

해시 테이블의 A부터 Z까지

해시를 사용하는 목적 - 해시 테이블: 해시테이블은 데이터의 해시 값을 테이블 내의 인덱스로 사용하는 자료구조이다. 필요한 데이터를 찾는 데 시간복잡도가 평균 O(1)인 굉장히 빠르게 데이터를 조회할 수 있다. - 암호화: 해시는 입력받은 데이터를 해시함수를 통해 원본의 모습을 전혀 알 수 없게 바꾼다. 이러한 해시의 특성 덕분에 해시는 암호화 영역에서 사용되고 있다. SHA 알고리즘이 대표적인 예이다. - 데이터 축약: 해시는 길이가 서로 다른 입력 데이터에 대해 일정한 길이의 출력을 만들 수 있다. 이 특성을 이용하면 대량 데이터를 해싱하여 짧은 길이로 축약할 수 있다. 해시 함수 해시테이블이란, 큰 숫자나 문자열을 해시 테이블의 인덱스로 사용할 수 있는 작은 정수로 매핑하는 함수이다. 해시함수를 고..

[LeetCode 23] Merge K Sorted Lists - 우선순위 큐

https://leetcode.com/problems/merge-k-sorted-lists/description/ 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 우선순위 큐에 정수를 넣는 방식 public ListNode mergeKLists(ListNode[] lists) { PriorityQueue pq = new PriorityQueue(); for (..

Algorithm/Leetcode 2024.02.05

[Leetcode 2] Add Two Numbers - 전가산기,연결리스트

https://leetcode.com/problems/add-two-numbers/ Add Two Numbers - LeetCode Can you solve this real interview question? Add Two Numbers - You are given two non-empty linked lists representing two non-negative integers. The digits are stored in reverse order, and each of their nodes contains a single digit. Add the two numbers and leetcode.com Problems 리스트 두개를 역순으로 만들고 연결리스트의 숫자를 더한다. 그다음 역순으로 리스트를..

Algorithm/Leetcode 2024.01.12

[Leetcode 234] Palindrome Linked List - 스택,데크,러너

https://leetcode.com/problems/palindrome-linked-list/ Palindrome Linked List - LeetCode Can you solve this real interview question? Palindrome Linked List - Given the head of a singly linked list, return true if it is a palindrome or false otherwise. Example 1: [https://assets.leetcode.com/uploads/2021/03/03/pal1linked-list.jpg] Input: hea leetcode.com Problem 연결 리스트가 팰린드롬 구조인지 true/false를 반환해라...

Algorithm/Leetcode 2024.01.04

[Leetcode 42] Trapping Rain Water - 투 포인터

https://leetcode.com/problems/trapping-rain-water/ Trapping Rain Water - LeetCode Can you solve this real interview question? Trapping Rain Water - Given n non-negative integers representing an elevation map where the width of each bar is 1, compute how much water it can trap after raining. Example 1: [https://assets.leetcode.com/upl leetcode.com Problem 높이를 입력 받아 얼마나 많은 물이 쌓일 수 있는 지 계산 입력 : [0,..

Algorithm/Leetcode 2023.12.26

[Leetcode 1] Two Sum - 4가지 방식의 풀이

https://leetcode.com/problems/two-sum/ 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 Problem 덧셈하여 target을 만들 수 있는 배열의 두 숫자 인덱스를 리턴. 인덱스 값은 유일하게 존재한다. 입력 : n..

Algorithm/Leetcode 2023.12.24

[Leetcode 5] Longest Palindromic Substring - 투 포인터+슬라이딩윈도우

https://leetcode.com/problems/longest-palindromic-substring/ = 0 && k < s.length() && s.charAt(j) == s.charAt(k)) { j--; k++; } if (maxLen < k - j - 1) { left = j + 1; maxLen = k - j - 1; } } public String longestPalindrome(String s) { int len = s.length(); if (len < 2) { return s; } for (int i = 0; i < len - 1; i++) { expand(s, i, i + 1); expand(s, i, i + 2); } return s.substring(left, left + m..

Algorithm/Leetcode 2023.12.21

[Leetcode 819] Most Common Word - 문자열처리

https://leetcode.com/problems/most-common-word/ Most Common Word - LeetCode Can you solve this real interview question? Most Common Word - Given a string paragraph and a string array of the banned words banned, return the most frequent word that is not banned. It is guaranteed there is at least one word that is not banned, and tha leetcode.com Problem 금지된 단어를 제외하고 가장 흔하게 등장하는 단어를 출력하라. 대소문자를 구분하..

Algorithm/Leetcode 2023.12.10