diff --git a/solution/172.Factorial Trailing Zeroes/Solution.cpp b/solution/172.Factorial Trailing Zeroes/Solution.cpp new file mode 100644 index 0000000000000..37800f12c4577 --- /dev/null +++ b/solution/172.Factorial Trailing Zeroes/Solution.cpp @@ -0,0 +1,9 @@ +class Solution { +public: + int trailingZeroes(int n) { + int cnt5 = 0 ; + for (long long i = 5; i <= n; i *= 5) + cnt5 += n/i ; + return cnt5 ; + } +}; \ No newline at end of file diff --git a/solution/190.Reverse Bits/Solution.cpp b/solution/190.Reverse Bits/Solution.cpp new file mode 100644 index 0000000000000..4d5eceaf2ada7 --- /dev/null +++ b/solution/190.Reverse Bits/Solution.cpp @@ -0,0 +1,16 @@ +class Solution { +public: + uint32_t reverseBits(uint32_t n) { + uint32_t res = 0 ; + uint32_t tmp = 1 << 31 ; + while (n) + { + if (n&1) + res |= tmp ; + tmp >>= 1 ; + n >>= 1 ; + } + + return res ; + } +}; \ No newline at end of file diff --git a/solution/434.Number of Segments in a String/Solution.cpp b/solution/434.Number of Segments in a String/Solution.cpp new file mode 100644 index 0000000000000..703920f4087d9 --- /dev/null +++ b/solution/434.Number of Segments in a String/Solution.cpp @@ -0,0 +1,13 @@ +class Solution { +public: + int countSegments(string s) { + if (s.length() < 1) + return 0 ; + + int cnt = isspace(s[0])? 0: 1 ; + for (int i = 1; i < s.length(); ++i) + if (!isspace(s[i]) && isspace(s[i-1])) + ++cnt ; + return cnt ; + } +}; \ No newline at end of file