Skip to content

Commit

Permalink
impl factorial trailing zeroes
Browse files Browse the repository at this point in the history
  • Loading branch information
SKTT1Ryze committed Mar 12, 2024
1 parent 6f8e197 commit 673c601
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
20 changes: 15 additions & 5 deletions leetcode-cc/FactorialTrailingZeroes.hpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#include <stack>

#include "TestHelper.h"
#include "problem.h"
#include "solution.h"
Expand All @@ -7,7 +9,8 @@ using namespace std;
IMPLEMENT_PROBLEM_CLASS(
PFactorialTrailingZeroes, 172, DIFFI_MEDIUM, TOPIC_ALGORITHMS,
"Factorial Trailing Zeroes",
"Given an integer n, return the number of trailing zeroes in n!.", {""});
"Given an integer n, return the number of trailing zeroes in n!.",
{"Math"});

class SFactorialTrailingZeroes : public ISolution {
public:
Expand All @@ -17,12 +20,19 @@ class SFactorialTrailingZeroes : public ISolution {
}
string location() const override { return __FILE_NAME__; }
int test() const override {
return testHelper<int, int>({3, 5, 0}, {0, 1, 0}, [this](auto input) {
return this->trailingZeroes(input);
});
return testHelper<int, int>(
{3, 5, 0, 6, 18}, {0, 1, 0, 1, 3},
[this](auto input) { return this->trailingZeroes(input); });
};
int benchmark() const override { return 0; }

private:
int trailingZeroes(int n) const {}
int trailingZeroes(int n) const {
int count = 0;
while (n > 0) {
count += n / 5;
n /= 5;
}
return count;
}
};
2 changes: 1 addition & 1 deletion leetcode-cc/FractionToDecimal.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ IMPLEMENT_PROBLEM_CLASS(
"Fraction to Recurring Decimal",
"Given two integers representing the numerator and denominator of a "
"fraction, return the fraction in string format.",
{""});
{"Math"});

class SFractionToDecimal : public ISolution {
public:
Expand Down

0 comments on commit 673c601

Please sign in to comment.