Skip to content

Factorial Trailing Zeroes #226

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Oct 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions Factorial Trailing Zeroes/CppSolutionFactorialTrailingZeroes.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
class Solution {
public:
int trailingZeroes(int n) {

int num = 5, ans = 0;

while(n/num) {

ans += n/num;
num *= 5;
}
return ans;
}
};
31 changes: 31 additions & 0 deletions Factorial Trailing Zeroes/Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# [Question Link](https://leetcode.com/problems/factorial-trailing-zeroes/)
Given an integer `n`, return the number of trailing zeroes in `n!`.

Note that `n! = n * (n - 1) * (n - 2) * ... * 3 * 2 * 1`.


Example 1:
```
Input: n = 3
Output: 0
Explanation: 3! = 6, no trailing zero.
```

Example 2:
```
Input: n = 5
Output: 1
Explanation: 5! = 120, one trailing zero.
```

Example 3:
```
Input: n = 0
Output: 0
```


Constraints:
```
0 <= n <= 10^4
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
class Solution {
public:
string findSub(int i, int j, string s) {

string ans = "";
while(i <= j) {

ans += s[i];
i++;
}

return ans;
}
string longestPalindrome(string s) {

int dp[s.length()][s.length()];
int max = 0;
string ans="";

for(int i = 0; i < s.length(); ++i) {

int st = 0, end = i;

for(int j = 0; j < s.length()-i; ++j) {

if(i > 1) {

dp[st][end] = 0;

if(s[st] == s[end] && dp[st+1][end-1]) {

dp[st][end] = 1;

if(end-st > max) {

ans = findSub(st, end, s);
max = end-st;
}
}
}
else {

if(i) {

dp[st][end] = 0;

if(s[st] == s[end]) {

dp[st][end] = 1;

if(end-st > max) {

ans = findSub(st, end, s);
max = end-st;
}
}
}
else {

dp[st][end] = 1;
ans = s[st];
max = 0;
}
}

st++;
end++;
}
}
return ans;
}
};
34 changes: 34 additions & 0 deletions Longest Palindromic Substring/Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# [Question Link](https://leetcode.com/problems/longest-palindromic-substring/)
Given a string` s`, return the longest palindromic substring in `s`.


Example 1:
```
Input: s = "babad"
Output: "bab"
Note: "aba" is also a valid answer.
```

Example 2:
```
Input: s = "cbbd"
Output: "bb"
```

Example 3:
```
Input: s = "a"
Output: "a"
```
Example 4:
```
Input: s = "ac"
Output: "a"
```

Constraints:
```
1 <= s.length <= 1000
s consist of only digits and English letters.

```