LeetCode 4. Median of Two Sorted Arrays
·
Algorithm/문제풀이
Median of Two Sorted Arrays - LeetCodeCan you solve this real interview question? Median of Two Sorted Arrays - Given two sorted arrays nums1 and nums2 of size m and n respectively, return the median of the two sorted arrays. The overall run time complexity should be O(log (m+n)). Example 1leetcode.com문제 설명크기가 m인 정렬된 배열 nums1 , 크기가 n인 정렬된 배열 nums2가 주어질 때 두 배열을 합쳤을 때 정렬된 배열의 중앙값을 반환하라실행시간 복잡도는 ..
LeetCode 33. Search in Rotated Sorted Array
·
Algorithm/문제풀이
Search in Rotated Sorted Array - LeetCodeCan you solve this real interview question? Search in Rotated Sorted Array - There is an integer array nums sorted in ascending order (with distinct values). Prior to being passed to your function, nums is possibly left rotated at an unknown index k (1 leetcode.com 문제 설명nums배열은 원래 오름차순으로 정렬된 배열에서 왼쪽으로 k번 회전한 배열이다예를 들러 nums가 [4,5,6,7,0,1,2] 로 주어지면원래 배열인 [0..
LeetCode 300. Longest Increasing Subsequence
·
Algorithm/문제풀이
Longest Increasing Subsequence - LeetCodeCan you solve this real interview question? Longest Increasing Subsequence - Given an integer array nums, return the length of the longest strictly increasing subsequence. Example 1: Input: nums = [10,9,2,5,3,7,101,18] Output: 4 Explanation: The longestleetcode.com문제 설명가장 기본적인 LIS 문제. nums 배열에서 가장 긴 증가하는 부분 수열의 길이를 반환하라.입력: nums = [10,9,2,5,3,7,101,18]출..
LeetCode 18. 4Sum
·
Algorithm/문제풀이
4Sum - LeetCodeCan you solve this real interview question? 4Sum - Given an array nums of n integers, return an array of all the unique quadruplets [nums[a], nums[b], nums[c], nums[d]] such that: * 0 leetcode.com문제 설명정수 n개의 nums 배열이 주어질 때 이 배열에서 4개의 수를 골라 이 값들을 다 더하여 target에 도달하는 고유한 4중 배열을 반환하시오 입력: nums = [1,0,-1,0,-2,2], target = 0출력: [[-2,-1,1,2],[-2,0,0,2],[-1,0,0,1]] 입력: nums = [2,2,2,2,2]..
LeetCode 329. Longest Increasing Path in a Matrix
·
Algorithm/문제풀이
Longest Increasing Path in a Matrix - LeetCodeCan you solve this real interview question? Longest Increasing Path in a Matrix - Given an m x n integers matrix, return the length of the longest increasing path in matrix. From each cell, you can either move in four directions: left, right, up, or down.leetcode.com 문제 설명2차원 행렬이 주어졌을 때 행렬에서 가장 긴 증가하는 경로의 길이를 구하시오입력: matrix = [[9,9,4],[6,6,8],[2,1,1]..
[알고리즘] 트라이
·
Algorithm/알고리즘
트라이문자열을 효율적으로 저장하고 탐색하기 위해 만들어진 트리 형태의 자료구조. - 문자열의 한 글자 한 글자가 트리의 노드가 됨. Root 노드는 비어 있고 자식 노드를 따라 내려가면서 단어가 완성되는 구조이다.예를 들어 문자 APPLE, APPLY, BANANA, BAN을 저장한다고 생각해 보자.일반적으로는 APPLE, APPLY... 각각 따로 저장할 텐데,하지만 트라이는 공통 접두사를 공유함.위 이미지에서 보면 APPLE와 APPLY에서 공통 접두사는 "APPL"까지임. 따라서 이제 이 공통되는 부분은 한 번만 저장하면 됨.이런 접두사를 이용하는 문제에서 매우 쓸모 있는 자료구조. - 자동완성 및 검색어 추천- 사전- 접두사 검색....시간 복잡도문자열 S에 대해 ⇒ 삽입 / 탐색 / 삭제 → O..