[leetCode] 169. Majority Element (Easy) 풀이 ❓ 문제 Given an array nums of size n, return the majority element. 크기가 n인 배열 개수가 주어지면 가장 많은 요소를 반환하세요. The majority element is the element that appears more than ⌊n / 2⌋ times. You may assume that the majority element always exists in the array. 가장 많은 요소는 ⌊n / 2⌋번 이상 나타나는 요소입니다. 가장 많은 요소가 항상 배열에 존재한다고 가정할 수 있습니다. Example 1: Input: nums = [3,2,3] Output: 3 Example 2: Input: nums = [2,2,1,1,1,2,2] O.. [leetCode] 136. Single Number (Easy) 풀이 ❓ 문제 Given a non-empty array of integers nums, every element appears twice except for one. Find that single one. 비어 있지 않은 정수 배열이 주어지면 모든 요소는 하나를 제외하고 두 번 나타납니다. 그 하나를 찾으십시오. You must implement a solution with a linear runtime complexity and use only constant extra space. 선형 런타임 복잡성이 있는 솔루션을 구현하고 일정한 추가 공간만 사용해야 합니다. Example 1: Input: nums = [2,2,1] Output: 1 Example 2: Input: nums = [4,1,2,1,2] .. [leetCode] 69. Sqrt(x) (Easy) 풀이 ❓ 문제 Given a non-negative integer x, compute and return the square root of x. 음이 아닌 정수 x가 주어지면 x의 제곱근을 계산하고 반환합니다. Since the return type is an integer, the decimal digits are truncated, and only the integer part of the result is returned. 리턴 타입이 정수이기 때문에 소수점 이하 자릿수는 잘리고 결과의 정수 부분만 리턴됩니다. Note: You are not allowed to use any built-in exponent function or operator, such as pow(x, 0.5) or x ** 0.5... [leetCode] 67. Add Binary (Easy) 풀이 ❓ 문제 Given two binary strings a and b, return their sum as a binary string. 두 개의 이진 문자열 a와 b가 주어지면 그 합을 이진 문자열로 반환합니다. Example 1: Input: a = "11", b = "1" Output: "100" Example 2: Input: a = "1010", b = "1011" Output: "10101" ❗ 내 답변 /** * @param {string} a * @param {string} b * @return {string} */ var addBinary = function(a, b) { const digitA = getDigit(a); const digitB = getDigit(b); const digi.. [leetCode] 66. Plus One (Easy) 풀이 ❓ 문제 You are given a large integer represented as an integer array digits, where each digits[i] is the ith digit of the integer. 정수 배열 자릿수로 표현되는 큰 정수가 주어집니다. 여기서 각 자릿수[i]는 정수의 i번째 자릿수입니다. The digits are ordered from most significant to least significant in left-to-right order. The large integer does not contain any leading 0's. 숫자는 왼쪽에서 오른쪽 순서로 최상위에서 최하위 순으로 정렬됩니다. 큰 정수에는 선행 0이 포함되지 않습니다. Increm.. [leetCode] 58. Length of Last Word (Easy) 풀이 ❓ 문제 Given a string s consisting of words and spaces, return the length of the last word in the string. 단어와 공백으로 구성된 문자열 s가 주어지면 문자열의 마지막 단어 길이를 반환합니다. A word is a maximal substring consisting of non-space characters only. 단어는 공백이 아닌 문자로만 구성된 최대 부분 문자열입니다. Example 1 Input: s = "Hello World" Output: 5 Explanation: The last word is "World" with length 5. Example 2 Input: s = " fly me to the moon ".. 이전 1 2 3 다음