목록leetcode (10)
Partially Committed
TITLE : 1822. Sign of the Product of an Array Description : There is a function signFunc(x) that returns: 1 if x is positive. -1 if x is negative. 0 if x is equal to 0. You are given an integer array nums. Let product be the product of all values in the array nums. Return signFunc(product). Example 1: Input: nums = [-1,-2,-3,-4,3,2,1] Output: 1 Explanation: The product of all values in the array..
TITLE : 1779.Find Nearest Point That Has the Same X or Y Coordinate Description : You are given two integers,xandy, which represent your current location on a Cartesian grid:(x, y). You are also given an arraypointswhere eachpoints[i] = [ai, bi]represents that a point exists at(ai, bi). A point isvalidif it shares the same x-coordinate or the same y-coordinate as your location. Return the index ..
TITLE : 1281. Subtract the Product and Sum of Digits of an Integer Description : Given an integer number n, return the difference between the product of its digits and the sum of its digits. 각 자릿수들의 곱과 각 자릿수들의 합의 차이를 반환하는 메서드를 구현하면된다 . [C++] class Solution { public: int subtractProductAndSum(int n) { int pod = 1; int sod = 0; int t = 0; string temp = to_string(n); vector v; for (char ele : temp)..
TITLE : 191.Number of 1 Bits Description : Write a function that takes an unsigned integer and returns the number of '1' bits it has (also known as the Hamming weight). 2진수로 나타냈을 때, 1 의 개수를 세어주면 된다. uint32_t n 을 입력받으면, n 이 0이 아닐 때 까지 1 과 and operator 을 수행한 결과를 ans 에 누적하고 n 을 right shift 해서 갱신해주면 된다. 혹은 bitset 을 이용하면 n bitset (n).count(); 으로 쉽게 구할 수도 있다. [C++] class Solution { public: int ..