분류 전체보기
-
[leetcode] 4. Median of Two Sorted Arrays (Typescript)Algorithm 2021. 2. 21. 13:59
Given two sorted arrays nums1 and nums2 of size m and n respectively, return the median of the two sorted arrays. Follow up: The overall run time complexity should be O(log (m+n)). Example 1: Input: nums1 = [1,3], nums2 = [2] Output: 2.00000 Explanation: merged array = [1,2,3] and median is 2. Example 2: Input: nums1 = [1,2], nums2 = [3,4] Output: 2.50000 Explanation: merged array = [1,2,3,4] an..
-
[leetcode] 3. Longest Substring Without Repeating Characters (Typescript)Algorithm 2021. 2. 20. 14:14
Given a string s, find the length of the longest substring without repeating characters Example 1: Input: s = "abcabcbb" Output: 3 Explanation: The answer is "abc", with the length of 3. Example 2: Input: s = "bbbbb" Output: 1 Explanation: The answer is "b", with the length of 1. Example 3: Input: s = "pwwkew" Output: 3 Explanation: The answer is "wke", with the length of 3. Notice that the answ..
-
[Algorithm] Sliding Window 알고리즘 (Javascript)Algorithm 2021. 2. 14. 14:24
배열이나 리스트의 요소들의 일정 범위 값을 비교할 때 사용하는 알고리즘 이름처럼 고정된 윈도우가 일정한 범위를 유지하면서 이동하는 알고리즘 시간복잡도: O(n) // 특정 크기의 부분 배열의 최대 값을 구하는 예제 function maxSumArr(arr, size) { let maxSum = 0; let tempSum = 0; if(arr.length < size) return null; for(let i = 0; i < size; i++) { tempSum += arr[i]; } tempSum = maxSum; for(let i = size; i < arr.length; i++) { tempSum = tempSum - arr[i - size] + arr[i]; maxSum = Math.max(temp..
-
[leetcode] 2. Add two numbers (Typescript)Algorithm 2021. 2. 13. 13:54
문제 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 return the sum as a linked list. You may assume the two numbers do not contain any leading zero, except the number 0 itself. Example 1: Input: l1 = [2,4,3], l2 = [5,6,4] Output: [7,0,8] Explanation: 34..
-
[leetcode] 1. Two Sum (Typescript)Algorithm 2021. 2. 12. 14:25
문제 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. Example 1: Input: nums = [2,7,11,15], target = 9 Output: [0,1] Output: Because nums[0] + nums[1] == 9, we return [0, 1]. Exam..
-
[Vue] Vue Apollo FragmentsJavaScript/Vue 2021. 2. 11. 13:56
query에 사용될 필드들을 재사용 할 수 있도록 해줌 // user-info.fragment.gql fragment UserInfo on User { firstName lastName age gender } // get-user.query.gql #import './user-info.fragmet.gql' query getUser($userId: Int!) { getUser(userId: $userId) { ...UserInfo friends { ...UserInfo } } }