๋ฌธ์
์ฝ๋
class Solution {
public:
string multiply(string num1, string num2) {
if(num1 == "0" || num2 == "0") return "0";
vector<int> v(num1.length() + num2.length(), 0);
for(int i = num1.length()-1; i >= 0; i--){
for(int k = num2.length()-1; k >= 0; k--){
int mul = (num1[i]-'0') * (num2[k]-'0') + v[i+k+1];
v[i+k+1] = mul % 10;
v[i+k] += mul / 10;
}
}
string result = "";
for(int i = 0; i <v.size(); i++){
if(v[i]==0&&i==0) continue;
result += v[i]+'0';
}
return result;
}
};
ํ์ด
BigInteger ๊ณฑ์ ์ฐ์ฐ์ ๊ตฌํํ๋ ๋ฌธ์ ์ ๋๋ค. ์ด๋ฐ ๋ฌธ์ ๋ฅผ ํ ๋๋ง๋ค ๋ฐ์ดํธ ์ ํ์ด ์๋ python์ด๋ ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ฅผ ์ ๊ณตํด์ฃผ๋ Java๋ฅผ ์ฌ์ฉํ๊ณ ์ถ....
'Algorithm ๐ง๐ปโ๐ป > Leetcode' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[Leetcode,c++] Search Insert Position (0) | 2021.11.09 |
---|---|
[Leetcode,c++] Find the City With the Smallest Number of Neighbors at a Threshold Distance (0) | 2021.11.07 |
[Leetcode,c++] Combination Sum (0) | 2021.11.07 |
[Leetcode,c++] Longest Common Subsequence (0) | 2021.10.23 |
[Leetcode,c++] Robot Bounded In Circle (0) | 2021.10.23 |
[Leetcode,c++] Two Sum (0) | 2021.10.23 |
๋๊ธ