From 4187c12d8c10586862db6e08e98ecf64a9671127 Mon Sep 17 00:00:00 2001 From: Santushti Sharma Date: Sat, 30 Oct 2021 19:01:31 +0530 Subject: [PATCH 1/5] Create LongestPalindromicSubstring.cpp --- .../LongestPalindromicSubstring.cpp | 72 +++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 Longest Palindromic Substring/LongestPalindromicSubstring.cpp diff --git a/Longest Palindromic Substring/LongestPalindromicSubstring.cpp b/Longest Palindromic Substring/LongestPalindromicSubstring.cpp new file mode 100644 index 0000000..7064870 --- /dev/null +++ b/Longest Palindromic Substring/LongestPalindromicSubstring.cpp @@ -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; + } +}; From 437566d49c7627ce66e58334e6a5b782eb1d01b0 Mon Sep 17 00:00:00 2001 From: Santushti Sharma Date: Sat, 30 Oct 2021 21:36:42 +0530 Subject: [PATCH 2/5] Rename LongestPalindromicSubstring.cpp to CppSolutionLongestPalindromicSubstring.cpp --- ...icSubstring.cpp => CppSolutionLongestPalindromicSubstring.cpp} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename Longest Palindromic Substring/{LongestPalindromicSubstring.cpp => CppSolutionLongestPalindromicSubstring.cpp} (100%) diff --git a/Longest Palindromic Substring/LongestPalindromicSubstring.cpp b/Longest Palindromic Substring/CppSolutionLongestPalindromicSubstring.cpp similarity index 100% rename from Longest Palindromic Substring/LongestPalindromicSubstring.cpp rename to Longest Palindromic Substring/CppSolutionLongestPalindromicSubstring.cpp From 5b6deb9dd97ff4d74422fdd6cf5bc1642aa4da2c Mon Sep 17 00:00:00 2001 From: Santushti Sharma Date: Sat, 30 Oct 2021 21:40:54 +0530 Subject: [PATCH 3/5] Create Readme.md --- Longest Palindromic Substring/Readme.md | 34 +++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 Longest Palindromic Substring/Readme.md diff --git a/Longest Palindromic Substring/Readme.md b/Longest Palindromic Substring/Readme.md new file mode 100644 index 0000000..7410271 --- /dev/null +++ b/Longest Palindromic Substring/Readme.md @@ -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. + +``` From 3315b42186037ab407166104a79a3bc44fa8fb9f Mon Sep 17 00:00:00 2001 From: Santushti Sharma Date: Sat, 30 Oct 2021 21:59:33 +0530 Subject: [PATCH 4/5] Create CppSolutionFactorialTrailingZeroes.cpp --- .../CppSolutionFactorialTrailingZeroes.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 Factorial Trailing Zeroes/CppSolutionFactorialTrailingZeroes.cpp diff --git a/Factorial Trailing Zeroes/CppSolutionFactorialTrailingZeroes.cpp b/Factorial Trailing Zeroes/CppSolutionFactorialTrailingZeroes.cpp new file mode 100644 index 0000000..e7307c8 --- /dev/null +++ b/Factorial Trailing Zeroes/CppSolutionFactorialTrailingZeroes.cpp @@ -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; + } +}; From 0457ed331a8e72a043cdbf33ab69eea7366de0f0 Mon Sep 17 00:00:00 2001 From: Santushti Sharma Date: Sat, 30 Oct 2021 22:03:41 +0530 Subject: [PATCH 5/5] Create Readme.md --- Factorial Trailing Zeroes/Readme.md | 31 +++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 Factorial Trailing Zeroes/Readme.md diff --git a/Factorial Trailing Zeroes/Readme.md b/Factorial Trailing Zeroes/Readme.md new file mode 100644 index 0000000..512e6cf --- /dev/null +++ b/Factorial Trailing Zeroes/Readme.md @@ -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 +```