Notice
Recent Posts
Recent Comments
- Today
- Total
01-10 22:06
Tags
- ๋ฐฑ์๋
- leetcode
- ์กธ์ ์ํ
- ๋ค์ต์คํธ๋ผ
- ๋ฒจ๋งํฌ๋
- ๊ตฌํ
- ์๋ฃ๊ตฌ์กฐ
- dp
- ์์์ ๋ ฌ
- CS
- ์๋ฐ์์ ์
- ๋ฌธ๋ฒ
- database
- ์ธํด
- Algorithm
- java
- spring
- ํ๋ก๊ทธ๋๋จธ์ค
- Graph
- OOP
- ๋ฐ์ดํฐ๋ฒ ์ด์ค
- array
- MST
- ๊ทธ๋ฆฌ๋
- ๋ฐฑ์ค
- PS
- BFS
- tree
- ์๋ฐ
- pytorch
Link
Partially Committed
[LEETCODE] 1281. Subtract the Product and Sum of Digits of an Integer ๋ณธ๋ฌธ
๐ฅ Algorithm || ๋ฌธ์ ํ์ด/PS
[LEETCODE] 1281. Subtract the Product and Sum of Digits of an Integer
WonderJay 2022. 10. 10. 14:42728x90
๋ฐ์ํ
SMALL
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<int> v;
for (char ele : temp) {
pod *= (ele - '0');
sod += (ele - '0');
}
return pod - sod;
}
};
๊ฐ ์๋ฆฟ์๋งํผ ์ํํ๋ฏ๋ก O(log(n)) ๋ฒ์ ์ฐ์ฐ์ด ํ์ํ๋ค.
์๊ฐ ๋ณต์ก๋ : O(logN)
728x90
๋ฐ์ํ
LIST
'๐ฅ Algorithm || ๋ฌธ์ ํ์ด > PS' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[LEETCODE] 1822. Sign of the Product of an Array (0) | 2022.10.12 |
---|---|
[LEETCODE] 1779.Find Nearest Point That Has the Same X or Y Coordinate (0) | 2022.10.11 |
[LEETCODE] 191.Number of 1 Bits (0) | 2022.10.10 |
[LEETCODE] 1491. Average Salary Excluding the Minimum and Maximum Salary (0) | 2022.10.09 |
[LEETCODE] 1523. Count Odd Numbers in an Interval Range (0) | 2022.10.09 |
Comments