본문 바로가기

알고리즘 문제풀이/leetcode142

[leetcode 88] Merge Sorted Array Given two sorted integer arrays nums1 and nums2, merge nums2 into nums1 as one sorted array. Note: The number of elements initialized in nums1 and nums2 are m and n respectively. You may assume that nums1 has enough space (size that is equal to m + n) to hold additional elements from nums2. Example: Input: nums1 = [1,2,3,0,0,0], m = 3 nums2 = [2,5,6], n = 3 Output: [1,2,2,3,5,6] Constraints: -10^9 2020. 11. 19.
[leetcode 69] Sqrt(x) Given a non-negative integer x, compute and return the square root of x. Since the return type is an integer, the decimal digits are truncated, and only the integer part of the result is returned. Example 1: Input: x = 4 Output: 2 Example 2: Input: x = 8 Output: 2 Explanation: The square root of 8 is 2.82842..., and since the decimal part is truncated, 2 is returned. Constraints: 0 2020. 11. 18.
[leetcode 50] Pow(x, n) Implement pow(x, n), which calculates x raised to the power n (i.e. xn). Example 1: Input: x = 2.00000, n = 10 Output: 1024.00000 Example 2: Input: x = 2.10000, n = 3 Output: 9.26100 Example 3: Input: x = 2.00000, n = -2 Output: 0.25000 Explanation: 2-2 = 1/22 = 1/4 = 0.25 Constraints: -100.0 0 X= 1에서 시작 IF N이 홀수 THEN 결과 * X IF N이 짝수 THEN X = X*X; N = N>>1; 또 다른 예시 A^ 13제곱을 확인해보자 그래서 다음과 같은 코드가 .. 2020. 11. 18.
[leetcode 26] Remove Duplicates from Sorted Array Given a sorted array nums, remove the duplicates in-place such that each element appears only once and returns 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. 정렬된 배열에서 중복된 수열을 제거한 요소가 앞에 오게 만들기. 그리고 중복된 요소를 제거한 길이를 return 0부터 len까지 배열을 print하므로 배열 변화가 반영된다. Clarification: Confused why the returned value.. 2020. 11. 18.