본문 바로가기

Web 프로그래밍/leetcode13

leetcode 35 - Search Insert Position Given a sorted array and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in order. You may assume no duplicates in the array. Example 1: Input: [1,3,5,6], 5 Output: 2 Example 2: Input: [1,3,5,6], 2 Output: 1 Example 3: Input: [1,3,5,6], 7 Output: 4 Example 4: Input: [1,3,5,6], 0 Output: 0 /** * @param {number[]} nums * @para.. 2019. 2. 27.
leetcode 202 - happy number Write an algorithm to determine if a number 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 squares of its digits, and repeat the process until the number equals 1 (where it will stay), or it loops endlessly in a cycle which does not include 1. Those numbers for which this process ends in 1 are happ.. 2019. 2. 27.
leetcode 26 - Remove Duplicates from Sorted Array Given a sorted array nums, remove the duplicates in-place such that each element appear only once and return the new length. Do not allocate extra space for another array, you must do this by modifying the input array in-place with O(1) extra memory. Example 1: Given nums = [1,1,2], Your function should return length = 2, with the first two elements of nums being 1 and 2 respectively. It doesn't.. 2019. 2. 25.
leetcode 21 - Merge Two Sorted Lists Merge two sorted linked lists and return it as a new list. The new list should be made by splicing together the nodes of the first two lists. 정렬 된 두 개의 링크 된 목록을 병합하고 새 목록으로 반환하십시오. 새 목록은 처음 두 목록의 노드를 서로 연결하여 만들어야합니다. /** * Definition for singly-linked list. * function ListNode(val) { * this.val = val; * this.next = null; * } */ /** * @param {ListNode} l1 * @param {ListNode} l2 * @return {ListNod.. 2019. 2. 22.
leetcode 20 - Valid Parentheses Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid. An input string is valid if: Open brackets must be closed by the same type of brackets. Open brackets must be closed in the correct order. Note that an empty string is also considered valid. '(', ')', '{', '}', '['및 ']'문자 만 들어있는 문자열을 입력 문자열이 유효한지 판단하십시오. 입력 문자열은 다음 경우에 유효합니다. 개방.. 2019. 2. 22.
leetcode 50 - Pow(x, n) Implement pow(x, n), which calculates x raised to the power n (xn). Power n (xn)으로 x를 계산하는 pow (x, n)을 구현합니다. /** * @param {number} x * @param {number} n * @return {number} */ var myPow = function(x, n) { return Math.pow(x, n).toFixed(5); }; 2019. 2. 19.