본문 바로가기
728x90

전체 글190

[LeetCode] 69. Sqrt(x) Given a non-negative integer x, return the square root of x rounded down to the nearest integer. The returned integer should be non-negative as well. You must not use any built-in exponent function or operator. For example, do not use pow(x, 0.5) in c++ or x ** 0.5 in python. Example 1: Input: x = 4 Output: 2 Explanation: The square root of 4 is 2, so we return 2. Example 2: Input: x = 8 Output:.. 2024. 2. 23.
[LeetCode] 68. Text Justification Given an array of strings words and a width maxWidth, format the text such that each line has exactly maxWidth characters and is fully (left and right) justified. You should pack your words in a greedy approach; that is, pack as many words as you can in each line. Pad extra spaces ' ' when necessary so that each line has exactly maxWidth characters. Extra spaces between words should be distribut.. 2024. 2. 19.
[LeetCode] 67. Add Binary Given two binary strings a and b, return their sum as a binary string. Example 1: Input: a = "11", b = "1" Output: "100" Example 2: Input: a = "1010", b = "1011" Output: "10101" Constraints: 1 = 0) { let sum = carry; if (i >= 0) sum += parseInt(a[i--]); if (j >= 0) sum += parseInt(b[j--]); // sum이 2보다 작으면 sum을 결과에 추가하고 carry는 0 // sum이 2라면 0을 결과에 추가하고 carry는 1 // sum이 3이라면 1을 결과에 추가하고 carry는 1 r.. 2024. 1. 30.
[LeetCode] 66. Plus One You are given a large integer represented as an integer array digits, where each digits[i] is the i^th digit of the integer. 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. Increment the large integer by one and return the resulting array of digits. Example 1: Input: digits = [1,2,3] Output: [1,2,4] Exp.. 2024. 1. 29.
728x90