반응형
https://leetcode.com/problems/convert-integer-to-the-sum-of-two-no-zero-integers/description/
LeetCode - The World's Leading Online Programming Learning Platform
Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.
leetcode.com
간단 구현 문제였습니다.
📕 풀이방법
📔 풀이과정
1 ~ n/2까지 for loop를 수행하면서 i 와 n - i에 0이 포함되어있는지 확인해 정답을 구할 수 있습니다.
📕 Code
📔 C++
class Solution {
public:
bool hasNoZero(int num) {
while(num > 0) {
if (num % 10 == 0) return false;
num /= 10;
}
return true;
}
vector<int> getNoZeroIntegers(int n) {
for(int i = 1; i <= n/2; i++) {
if(hasNoZero(i) && hasNoZero(n-i)) return {i, n-i};
}
return {};
}
};
*더 나은 내용을 위한 지적, 조언은 언제나 환영합니다.
'Algorithm > Implementation' 카테고리의 다른 글
(SQL) - LeetCode (easy) 1327. List the Products Ordered in a Period (0) | 2024.02.01 |
---|---|
(C++) - LeetCode (easy) 1323. Maximum 69 Number (1) | 2024.01.31 |
(C++) - LeetCode (easy) 1313. Decompress Run-Length Encoded List (0) | 2024.01.26 |
(C++) - LeetCode (easy) 1304. Find N Unique Integers Sum up to Zero (0) | 2024.01.23 |
(C++) - LeetCode (easy) 1295. Find Numbers with Even Number of Digits (0) | 2024.01.19 |