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..
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..
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..
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. '(', ')', '{', '}', '['및 ']'문자 만 들어있는 문자열을 입력 문자열이 유효한지 판단하십시오. 입력 문자열은 다음 경우에 유효합니다. 개방..
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); };
Write a function to find the longest common prefix string amongst an array of strings. If there is no common prefix, return an empty string "". 문자열 배열 사이에서 가장 긴 공통 접두사 문자열을 찾는 함수를 작성하십시오. 공통 접두사가없는 경우 빈 문자열 ""을 반환합니다. I used to eval function. If you use a different language, the code below will not work 자바스크립트이 eval 이라는 특수 함수를 사용해서 풀었다. 다른언어로 푼다면 다른 알고리즘을 사용해야 할 것입니다. /** * @param {string[]} str..