From 57ad31a460d27b3150dd77c963cdcbe6348502d9 Mon Sep 17 00:00:00 2001 From: Imtiaz Ahmed Date: Mon, 24 Feb 2020 13:23:56 -0700 Subject: [PATCH 01/18] PalindromeNumber added - solution by Imtiaz --- src/PalindromeNumber/README.md | 30 ++++++++++++++ src/PalindromeNumber/Solution.cpp | 66 +++++++++++++++++++++++++++++++ 2 files changed, 96 insertions(+) create mode 100644 src/PalindromeNumber/README.md create mode 100644 src/PalindromeNumber/Solution.cpp diff --git a/src/PalindromeNumber/README.md b/src/PalindromeNumber/README.md new file mode 100644 index 0000000..4de15a4 --- /dev/null +++ b/src/PalindromeNumber/README.md @@ -0,0 +1,30 @@ +# Palindrome Number + +LeetCode [source](https://leetcode.com/problems/palindrome-number/) + +## Solution + +### Intuition + +The challenge with this problem is that you're not allowed to use any string. You have to take the integer and come up with a solution that doesn't employ string or any of its methods. From the first glance, what was apparent is that we'll need a data structure to hold the individual integers for comparison. + +### Algorithm +The algorithm for the solution is as follows: +1. If it's a single digit, then it's a Palindrome Number. +2. Ignore any negative integers. +3. For all other types of integers, pop each digit and store them in a vector in order. +4. Compare the `(n + i)th` integer with `(vector.size() - 1 - i)th integer. +5. If this comparisos fails (i.e. `comparison == false`) return false. +6. Else continue the comparisons until `i` reaches the middle of the vector. If no `false` was return before, it means all the comparisons were `true` and therefore, the integer is a palindrome. + +### Complexity Analysis +* Time Complexity: `// TODO` +* Space Complexity: `// TODO` + +### AC Result + +`11509 / 11509 test cases passed` + +| Status | Runtime | Memory | +|--------|---------|--------| +| Accepted | 36 ms | 11.7 MB | \ No newline at end of file diff --git a/src/PalindromeNumber/Solution.cpp b/src/PalindromeNumber/Solution.cpp new file mode 100644 index 0000000..02e5daf --- /dev/null +++ b/src/PalindromeNumber/Solution.cpp @@ -0,0 +1,66 @@ +#include +#include + +using namespace std; + +class Solution { +public: + bool isPalindrome(int x) { + if (x >= 0 && x < 10) { + return true; + } + else if (x >= 10) { + vector vec; + long div = 10; + long ct = 1; + int num = 0; + int digCount = 0; + int temp = x; + + while (temp != 0) { + temp /= 10; + digCount++; + } + + for (int i = 0; i < digCount; i++) { + num = x % div; + num /= ct; + div *= 10; + ct *= 10; + vec.push_back(num); + } + + for (int i = 0; i < vec.size(); i++) { + if (i == vec.size() - 1) return true; + else if (vec[i] != vec[vec.size() - 1 - i]) return false; + } + + } + else { + return false; + } + + return false; +}; +}; + +int stringToInteger(string input) { + return stoi(input); +} + +string boolToString(bool input) { + return input ? "True" : "False"; +} + +int main() { + string line; + while (getline(cin, line)) { + int x = stringToInteger(line); + + bool ret = Solution().isPalindrome(x); + + string out = boolToString(ret); + cout << out << endl; + } + return 0; +} \ No newline at end of file From c41019af0e2ac24d25df8201861482b38e292349 Mon Sep 17 00:00:00 2001 From: Imtiaz Ahmed Date: Mon, 24 Feb 2020 13:32:13 -0700 Subject: [PATCH 02/18] feat: PalindromeNumber Solution Added --- src/PalindromeNumber/README.md | 2 +- src/PalindromeNumber/Solution.cpp | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/PalindromeNumber/README.md b/src/PalindromeNumber/README.md index 4de15a4..b1bd184 100644 --- a/src/PalindromeNumber/README.md +++ b/src/PalindromeNumber/README.md @@ -9,7 +9,7 @@ LeetCode [source](https://leetcode.com/problems/palindrome-number/) The challenge with this problem is that you're not allowed to use any string. You have to take the integer and come up with a solution that doesn't employ string or any of its methods. From the first glance, what was apparent is that we'll need a data structure to hold the individual integers for comparison. ### Algorithm -The algorithm for the solution is as follows: +Details of the the algorithm for the solution is as follows: 1. If it's a single digit, then it's a Palindrome Number. 2. Ignore any negative integers. 3. For all other types of integers, pop each digit and store them in a vector in order. diff --git a/src/PalindromeNumber/Solution.cpp b/src/PalindromeNumber/Solution.cpp index 02e5daf..7b27386 100644 --- a/src/PalindromeNumber/Solution.cpp +++ b/src/PalindromeNumber/Solution.cpp @@ -1,3 +1,5 @@ +// Solution by Imtiaz Ahmed (Github: tiazahmd) + #include #include From a1a3e29cdd8d98192bd11ecb4d4609ea9f0f8078 Mon Sep 17 00:00:00 2001 From: Imtiaz Ahmed Date: Tue, 25 Feb 2020 05:17:47 -0700 Subject: [PATCH 03/18] Update src/PalindromeNumber/README.md Co-Authored-By: He Linming --- src/PalindromeNumber/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/PalindromeNumber/README.md b/src/PalindromeNumber/README.md index b1bd184..cb68da5 100644 --- a/src/PalindromeNumber/README.md +++ b/src/PalindromeNumber/README.md @@ -13,7 +13,7 @@ Details of the the algorithm for the solution is as follows: 1. If it's a single digit, then it's a Palindrome Number. 2. Ignore any negative integers. 3. For all other types of integers, pop each digit and store them in a vector in order. -4. Compare the `(n + i)th` integer with `(vector.size() - 1 - i)th integer. +4. Compare the `(n + i)th` integer with `(vector.size() - 1 - i)th` integer. 5. If this comparisos fails (i.e. `comparison == false`) return false. 6. Else continue the comparisons until `i` reaches the middle of the vector. If no `false` was return before, it means all the comparisons were `true` and therefore, the integer is a palindrome. @@ -27,4 +27,4 @@ Details of the the algorithm for the solution is as follows: | Status | Runtime | Memory | |--------|---------|--------| -| Accepted | 36 ms | 11.7 MB | \ No newline at end of file +| Accepted | 36 ms | 11.7 MB | From 555e5a691640534a7f4f84eb65cbfd586dad3a26 Mon Sep 17 00:00:00 2001 From: Imtiaz Ahmed Date: Tue, 25 Feb 2020 05:52:07 -0700 Subject: [PATCH 04/18] fix: clang-format and source file --- .clang-format | 25 +++++++-- src/PalindromeNumber/Solution.cpp | 92 +++++++++++++++---------------- 2 files changed, 63 insertions(+), 54 deletions(-) diff --git a/.clang-format b/.clang-format index 4b76204..838938d 100644 --- a/.clang-format +++ b/.clang-format @@ -3,24 +3,29 @@ Language: Cpp # BasedOnStyle: LLVM AccessModifierOffset: -2 AlignAfterOpenBracket: Align +AlignConsecutiveMacros: false AlignConsecutiveAssignments: false AlignConsecutiveDeclarations: false AlignEscapedNewlines: Right AlignOperands: true AlignTrailingComments: true +AllowAllArgumentsOnNextLine: true +AllowAllConstructorInitializersOnNextLine: true AllowAllParametersOfDeclarationOnNextLine: true AllowShortBlocksOnASingleLine: false AllowShortCaseLabelsOnASingleLine: false AllowShortFunctionsOnASingleLine: All -AllowShortIfStatementsOnASingleLine: false +AllowShortLambdasOnASingleLine: All +AllowShortIfStatementsOnASingleLine: Never AllowShortLoopsOnASingleLine: false AlwaysBreakAfterDefinitionReturnType: None AlwaysBreakAfterReturnType: None AlwaysBreakBeforeMultilineStrings: false -AlwaysBreakTemplateDeclarations: false +AlwaysBreakTemplateDeclarations: MultiLine BinPackArguments: true BinPackParameters: true BraceWrapping: + AfterCaseLabel: false AfterClass: false AfterControlStatement: false AfterEnum: false @@ -39,6 +44,7 @@ BraceWrapping: BreakBeforeBinaryOperators: None BreakBeforeBraces: Attach BreakBeforeInheritanceComma: false +BreakInheritanceList: BeforeColon BreakBeforeTernaryOperators: true BreakConstructorInitializersBeforeComma: false BreakConstructorInitializers: BeforeColon @@ -79,6 +85,7 @@ MacroBlockBegin: '' MacroBlockEnd: '' MaxEmptyLinesToKeep: 1 NamespaceIndentation: None +ObjCBinPackProtocolList: Auto ObjCBlockIndentWidth: 2 ObjCSpaceAfterProperty: false ObjCSpaceBeforeProtocolList: true @@ -87,20 +94,22 @@ PenaltyBreakBeforeFirstCallParameter: 19 PenaltyBreakComment: 300 PenaltyBreakFirstLessLess: 120 PenaltyBreakString: 1000 +PenaltyBreakTemplateDeclaration: 10 PenaltyExcessCharacter: 1000000 PenaltyReturnTypeOnItsOwnLine: 60 PointerAlignment: Right -RawStringFormats: - - Delimiter: pb - Language: TextProto - BasedOnStyle: google ReflowComments: true SortIncludes: true SortUsingDeclarations: true SpaceAfterCStyleCast: false +SpaceAfterLogicalNot: false SpaceAfterTemplateKeyword: true SpaceBeforeAssignmentOperators: true +SpaceBeforeCpp11BracedList: false +SpaceBeforeCtorInitializerColon: true +SpaceBeforeInheritanceColon: true SpaceBeforeParens: ControlStatements +SpaceBeforeRangeBasedForLoopColon: true SpaceInEmptyParentheses: false SpacesBeforeTrailingComments: 1 SpacesInAngles: false @@ -109,6 +118,10 @@ SpacesInCStyleCastParentheses: false SpacesInParentheses: false SpacesInSquareBrackets: false Standard: Cpp11 +StatementMacros: + - Q_UNUSED + - QT_REQUIRE_VERSION TabWidth: 8 UseTab: Never ... + diff --git a/src/PalindromeNumber/Solution.cpp b/src/PalindromeNumber/Solution.cpp index 7b27386..27a5d9b 100644 --- a/src/PalindromeNumber/Solution.cpp +++ b/src/PalindromeNumber/Solution.cpp @@ -7,62 +7,58 @@ using namespace std; class Solution { public: - bool isPalindrome(int x) { - if (x >= 0 && x < 10) { - return true; - } - else if (x >= 10) { - vector vec; - long div = 10; - long ct = 1; - int num = 0; - int digCount = 0; - int temp = x; + bool isPalindrome(int x) { + if (x >= 0 && x < 10) { + return true; + } else if (x >= 10) { + vector vec; + long div = 10; + long ct = 1; + int num = 0; + int digCount = 0; + int temp = x; - while (temp != 0) { - temp /= 10; - digCount++; - } + while (temp != 0) { + temp /= 10; + digCount++; + } - for (int i = 0; i < digCount; i++) { - num = x % div; - num /= ct; - div *= 10; - ct *= 10; - vec.push_back(num); - } - - for (int i = 0; i < vec.size(); i++) { - if (i == vec.size() - 1) return true; - else if (vec[i] != vec[vec.size() - 1 - i]) return false; - } + for (int i = 0; i < digCount; i++) { + num = x % div; + num /= ct; + div *= 10; + ct *= 10; + vec.push_back(num); + } + + for (int i = 0; i < vec.size(); i++) { + if (i == vec.size() - 1) + return true; + else if (vec[i] != vec[vec.size() - 1 - i]) + return false; + } + + } else { + return false; + } - } - else { - return false; - } - return false; -}; + }; }; -int stringToInteger(string input) { - return stoi(input); -} +int stringToInteger(string input) { return stoi(input); } -string boolToString(bool input) { - return input ? "True" : "False"; -} +string boolToString(bool input) { return input ? "True" : "False"; } int main() { - string line; - while (getline(cin, line)) { - int x = stringToInteger(line); - - bool ret = Solution().isPalindrome(x); + string line; + while (getline(cin, line)) { + int x = stringToInteger(line); - string out = boolToString(ret); - cout << out << endl; - } - return 0; + bool ret = Solution().isPalindrome(x); + + string out = boolToString(ret); + cout << out << endl; + } + return 0; } \ No newline at end of file From 4fd85b7be3036e057c631e84a9fa999f1609a6df Mon Sep 17 00:00:00 2001 From: Imtiaz Ahmed Date: Tue, 25 Feb 2020 15:23:28 -0700 Subject: [PATCH 05/18] test: added test --- src/PalindromeNumber/Solution.cpp | 40 +++++++++++++++++++++---------- 1 file changed, 27 insertions(+), 13 deletions(-) diff --git a/src/PalindromeNumber/Solution.cpp b/src/PalindromeNumber/Solution.cpp index 27a5d9b..986cbe8 100644 --- a/src/PalindromeNumber/Solution.cpp +++ b/src/PalindromeNumber/Solution.cpp @@ -3,13 +3,16 @@ #include #include +#include "../Test.h" + using namespace std; +using namespace leetcode; class Solution { public: - bool isPalindrome(int x) { + string isPalindrome(int x) { if (x >= 0 && x < 10) { - return true; + return "true"; } else if (x >= 10) { vector vec; long div = 10; @@ -33,16 +36,16 @@ class Solution { for (int i = 0; i < vec.size(); i++) { if (i == vec.size() - 1) - return true; + return "true"; else if (vec[i] != vec[vec.size() - 1 - i]) - return false; + return "false"; } } else { - return false; + return "false"; } - return false; + return "false"; }; }; @@ -51,14 +54,25 @@ int stringToInteger(string input) { return stoi(input); } string boolToString(bool input) { return input ? "True" : "False"; } int main() { - string line; - while (getline(cin, line)) { - int x = stringToInteger(line); - bool ret = Solution().isPalindrome(x); + Solution s; + + test("Test case: ", s.isPalindrome(121), "true"); + test("Test case: ", s.isPalindrome(120), "true"); + test("Test case: ", s.isPalindrome(-121), "true"); + test("Test case: ", s.isPalindrome(11), "true"); + test("Test case: ", s.isPalindrome(9), "true"); + test("Test case: ", s.isPalindrome(0), "true"); + test("Test case: ", s.isPalindrome(10022001), "true"); + + // string line; + // while (getline(cin, line)) { + // int x = stringToInteger(line); + + // bool ret = Solution().isPalindrome(x); - string out = boolToString(ret); - cout << out << endl; - } + // string out = boolToString(ret); + // cout << out << endl; + // } return 0; } \ No newline at end of file From 9853a5589de4b426ce8ca48b3785a8ff9aa0c629 Mon Sep 17 00:00:00 2001 From: Imtiaz Ahmed Date: Tue, 25 Feb 2020 15:27:18 -0700 Subject: [PATCH 06/18] fix: markdown --- src/PalindromeNumber/README.md | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/PalindromeNumber/README.md b/src/PalindromeNumber/README.md index cb68da5..058eabf 100644 --- a/src/PalindromeNumber/README.md +++ b/src/PalindromeNumber/README.md @@ -9,15 +9,18 @@ LeetCode [source](https://leetcode.com/problems/palindrome-number/) The challenge with this problem is that you're not allowed to use any string. You have to take the integer and come up with a solution that doesn't employ string or any of its methods. From the first glance, what was apparent is that we'll need a data structure to hold the individual integers for comparison. ### Algorithm + Details of the the algorithm for the solution is as follows: -1. If it's a single digit, then it's a Palindrome Number. + +1. If it's a single digit, then it's a Palindrome Number. 2. Ignore any negative integers. 3. For all other types of integers, pop each digit and store them in a vector in order. -4. Compare the `(n + i)th` integer with `(vector.size() - 1 - i)th` integer. -5. If this comparisos fails (i.e. `comparison == false`) return false. +4. Compare the `(n + i)th` integer with `(vector.size() - 1 - i)th` integer. +5. If this comparisos fails (i.e. `comparison == false`) return false. 6. Else continue the comparisons until `i` reaches the middle of the vector. If no `false` was return before, it means all the comparisons were `true` and therefore, the integer is a palindrome. ### Complexity Analysis + * Time Complexity: `// TODO` * Space Complexity: `// TODO` From 7a2f0914941aa325cc7d2554157f1919be419e69 Mon Sep 17 00:00:00 2001 From: Imtiaz Ahmed Date: Wed, 26 Feb 2020 11:58:30 -0700 Subject: [PATCH 07/18] fix: changes according to new feedback --- src/PalindromeNumber/README.md | 4 +-- src/PalindromeNumber/Solution.cpp | 44 +++++++++++++------------------ 2 files changed, 20 insertions(+), 28 deletions(-) diff --git a/src/PalindromeNumber/README.md b/src/PalindromeNumber/README.md index 058eabf..a167b85 100644 --- a/src/PalindromeNumber/README.md +++ b/src/PalindromeNumber/README.md @@ -21,8 +21,8 @@ Details of the the algorithm for the solution is as follows: ### Complexity Analysis -* Time Complexity: `// TODO` -* Space Complexity: `// TODO` +* Time Complexity: `O(log⁡(n))` +* Space Complexity: `O(log⁡(n))` ### AC Result diff --git a/src/PalindromeNumber/Solution.cpp b/src/PalindromeNumber/Solution.cpp index 986cbe8..d270006 100644 --- a/src/PalindromeNumber/Solution.cpp +++ b/src/PalindromeNumber/Solution.cpp @@ -10,60 +10,52 @@ using namespace leetcode; class Solution { public: - string isPalindrome(int x) { + bool isPalindrome(int x) { if (x >= 0 && x < 10) { - return "true"; + return true; } else if (x >= 10) { vector vec; long div = 10; - long ct = 1; int num = 0; - int digCount = 0; int temp = x; while (temp != 0) { - temp /= 10; - digCount++; - } - - for (int i = 0; i < digCount; i++) { - num = x % div; - num /= ct; - div *= 10; - ct *= 10; + num = temp % div; + temp = temp / div; vec.push_back(num); } for (int i = 0; i < vec.size(); i++) { if (i == vec.size() - 1) - return "true"; + return true; else if (vec[i] != vec[vec.size() - 1 - i]) - return "false"; + return false; } } else { - return "false"; + return false; } - return "false"; + return false; }; }; -int stringToInteger(string input) { return stoi(input); } +// int stringToInteger(string input) { return stoi(input); } -string boolToString(bool input) { return input ? "True" : "False"; } +// string boolToString(bool input) { return input ? "True" : "False"; } int main() { Solution s; - test("Test case: ", s.isPalindrome(121), "true"); - test("Test case: ", s.isPalindrome(120), "true"); - test("Test case: ", s.isPalindrome(-121), "true"); - test("Test case: ", s.isPalindrome(11), "true"); - test("Test case: ", s.isPalindrome(9), "true"); - test("Test case: ", s.isPalindrome(0), "true"); - test("Test case: ", s.isPalindrome(10022001), "true"); + test("Test case: ", s.isPalindrome(121), true); + test("Test case: ", s.isPalindrome(120), false); + test("Test case: ", s.isPalindrome(-121), false); + test("Test case: ", s.isPalindrome(11), true); + test("Test case: ", s.isPalindrome(9), true); + test("Test case: ", s.isPalindrome(0), true); + test("Test case: ", s.isPalindrome(10022001), true); + test("Test case: ", s.isPalindrome(1001), true); // string line; // while (getline(cin, line)) { From 57058aa0dd9a3f26ddf71eeac66d711fd1f8200c Mon Sep 17 00:00:00 2001 From: Imtiaz Ahmed Date: Thu, 27 Feb 2020 05:15:34 -0700 Subject: [PATCH 08/18] docs: updated master README and clang-format --- .clang-format | 27 +++++++-------------------- README.md | 1 + 2 files changed, 8 insertions(+), 20 deletions(-) diff --git a/.clang-format b/.clang-format index 838938d..5281c9f 100644 --- a/.clang-format +++ b/.clang-format @@ -3,29 +3,24 @@ Language: Cpp # BasedOnStyle: LLVM AccessModifierOffset: -2 AlignAfterOpenBracket: Align -AlignConsecutiveMacros: false AlignConsecutiveAssignments: false AlignConsecutiveDeclarations: false AlignEscapedNewlines: Right AlignOperands: true AlignTrailingComments: true -AllowAllArgumentsOnNextLine: true -AllowAllConstructorInitializersOnNextLine: true AllowAllParametersOfDeclarationOnNextLine: true AllowShortBlocksOnASingleLine: false AllowShortCaseLabelsOnASingleLine: false AllowShortFunctionsOnASingleLine: All -AllowShortLambdasOnASingleLine: All -AllowShortIfStatementsOnASingleLine: Never +AllowShortIfStatementsOnASingleLine: false AllowShortLoopsOnASingleLine: false AlwaysBreakAfterDefinitionReturnType: None AlwaysBreakAfterReturnType: None AlwaysBreakBeforeMultilineStrings: false -AlwaysBreakTemplateDeclarations: MultiLine +AlwaysBreakTemplateDeclarations: false BinPackArguments: true BinPackParameters: true BraceWrapping: - AfterCaseLabel: false AfterClass: false AfterControlStatement: false AfterEnum: false @@ -44,7 +39,6 @@ BraceWrapping: BreakBeforeBinaryOperators: None BreakBeforeBraces: Attach BreakBeforeInheritanceComma: false -BreakInheritanceList: BeforeColon BreakBeforeTernaryOperators: true BreakConstructorInitializersBeforeComma: false BreakConstructorInitializers: BeforeColon @@ -85,7 +79,6 @@ MacroBlockBegin: '' MacroBlockEnd: '' MaxEmptyLinesToKeep: 1 NamespaceIndentation: None -ObjCBinPackProtocolList: Auto ObjCBlockIndentWidth: 2 ObjCSpaceAfterProperty: false ObjCSpaceBeforeProtocolList: true @@ -94,22 +87,20 @@ PenaltyBreakBeforeFirstCallParameter: 19 PenaltyBreakComment: 300 PenaltyBreakFirstLessLess: 120 PenaltyBreakString: 1000 -PenaltyBreakTemplateDeclaration: 10 PenaltyExcessCharacter: 1000000 PenaltyReturnTypeOnItsOwnLine: 60 PointerAlignment: Right +RawStringFormats: + - Delimiter: pb + Language: TextProto + BasedOnStyle: google ReflowComments: true SortIncludes: true SortUsingDeclarations: true SpaceAfterCStyleCast: false -SpaceAfterLogicalNot: false SpaceAfterTemplateKeyword: true SpaceBeforeAssignmentOperators: true -SpaceBeforeCpp11BracedList: false -SpaceBeforeCtorInitializerColon: true -SpaceBeforeInheritanceColon: true SpaceBeforeParens: ControlStatements -SpaceBeforeRangeBasedForLoopColon: true SpaceInEmptyParentheses: false SpacesBeforeTrailingComments: 1 SpacesInAngles: false @@ -118,10 +109,6 @@ SpacesInCStyleCastParentheses: false SpacesInParentheses: false SpacesInSquareBrackets: false Standard: Cpp11 -StatementMacros: - - Q_UNUSED - - QT_REQUIRE_VERSION TabWidth: 8 UseTab: Never -... - +... \ No newline at end of file diff --git a/README.md b/README.md index f6cc7d6..6b2b103 100644 --- a/README.md +++ b/README.md @@ -11,5 +11,6 @@ Code is easy to understand, documentation is pretty, and program performance is | Num | Problem | Solution | Time \| Space Complexity | Difficulty | |-----|---------|----------|--------------------------|------------| | 7 | [Reverse Integer](https://leetcode.com/problems/reverse-integer/) | [Code](./src/ReverseInteger/Solution.cpp) | O(log(n)) \| O(1) | Easy | +| 9 | [Palindrome Number](https://leetcode.com/problems/palindrome-number/) | [Code](./src/PalindromeNumber/Solution.cpp) | O(log(n)) \| O(log(n)) | Easy | | 13 | [Roman to Integer](https://leetcode.com/problems/roman-to-integer/) | [Code](./src/RomanToInteger/Solution.cpp) | O(n) \| O(1) | Easy | | 14 | [Longest Common Prefix](https://leetcode.com/problems/longest-common-prefix/) | [Code](./src/LongestCommonPrefix/Solution.cpp) | O(n) \| O(n) | Easy | From 7198fd779cad212ad587061fbcbd9d52b0614c3d Mon Sep 17 00:00:00 2001 From: Imtiaz Ahmed Date: Thu, 27 Feb 2020 07:24:55 -0700 Subject: [PATCH 09/18] fix: cleaned code and added new lines --- .clang-format | 1 + src/PalindromeNumber/Solution.cpp | 15 +-------------- 2 files changed, 2 insertions(+), 14 deletions(-) diff --git a/.clang-format b/.clang-format index 5281c9f..f0ca9d3 100644 --- a/.clang-format +++ b/.clang-format @@ -111,4 +111,5 @@ SpacesInSquareBrackets: false Standard: Cpp11 TabWidth: 8 UseTab: Never + ... \ No newline at end of file diff --git a/src/PalindromeNumber/Solution.cpp b/src/PalindromeNumber/Solution.cpp index d270006..19b7786 100644 --- a/src/PalindromeNumber/Solution.cpp +++ b/src/PalindromeNumber/Solution.cpp @@ -40,10 +40,6 @@ class Solution { }; }; -// int stringToInteger(string input) { return stoi(input); } - -// string boolToString(bool input) { return input ? "True" : "False"; } - int main() { Solution s; @@ -57,14 +53,5 @@ int main() { test("Test case: ", s.isPalindrome(10022001), true); test("Test case: ", s.isPalindrome(1001), true); - // string line; - // while (getline(cin, line)) { - // int x = stringToInteger(line); - - // bool ret = Solution().isPalindrome(x); - - // string out = boolToString(ret); - // cout << out << endl; - // } return 0; -} \ No newline at end of file +} From 8ffedac5e9da731b13213da8dbd6ed076ae700b7 Mon Sep 17 00:00:00 2001 From: Imtiaz Ahmed Date: Wed, 4 Mar 2020 10:17:34 -0700 Subject: [PATCH 10/18] fix: clang-format file --- .clang-format | 2 -- 1 file changed, 2 deletions(-) diff --git a/.clang-format b/.clang-format index f0ca9d3..00ac624 100644 --- a/.clang-format +++ b/.clang-format @@ -111,5 +111,3 @@ SpacesInSquareBrackets: false Standard: Cpp11 TabWidth: 8 UseTab: Never - -... \ No newline at end of file From 443769c1449f8ab83b8611b03c682830c2c00af6 Mon Sep 17 00:00:00 2001 From: Imtiaz Ahmed Date: Wed, 4 Mar 2020 10:17:57 -0700 Subject: [PATCH 11/18] fix: clang-format file --- .clang-format | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.clang-format b/.clang-format index 00ac624..95a9247 100644 --- a/.clang-format +++ b/.clang-format @@ -110,4 +110,4 @@ SpacesInParentheses: false SpacesInSquareBrackets: false Standard: Cpp11 TabWidth: 8 -UseTab: Never +UseTab: Never \ No newline at end of file From 195013e3b7296ccbfd075798703d4c4a9fce0ef1 Mon Sep 17 00:00:00 2001 From: Imtiaz Ahmed Date: Wed, 4 Mar 2020 10:20:05 -0700 Subject: [PATCH 12/18] fix: clang-format file --- .clang-format | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.clang-format b/.clang-format index 95a9247..5281c9f 100644 --- a/.clang-format +++ b/.clang-format @@ -110,4 +110,5 @@ SpacesInParentheses: false SpacesInSquareBrackets: false Standard: Cpp11 TabWidth: 8 -UseTab: Never \ No newline at end of file +UseTab: Never +... \ No newline at end of file From fa23a6fc9bb589eba90e1548fa3f024235be0505 Mon Sep 17 00:00:00 2001 From: Imtiaz Ahmed Date: Wed, 4 Mar 2020 10:20:26 -0700 Subject: [PATCH 13/18] fix: clang-format file --- .clang-format | 1 - 1 file changed, 1 deletion(-) diff --git a/.clang-format b/.clang-format index 5281c9f..00ac624 100644 --- a/.clang-format +++ b/.clang-format @@ -111,4 +111,3 @@ SpacesInSquareBrackets: false Standard: Cpp11 TabWidth: 8 UseTab: Never -... \ No newline at end of file From 75dd4ffd0068d68953fcb24d5f9fa58d54dc085b Mon Sep 17 00:00:00 2001 From: Imtiaz Ahmed Date: Wed, 4 Mar 2020 10:20:40 -0700 Subject: [PATCH 14/18] fix: clang-format file --- .clang-format | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.clang-format b/.clang-format index 00ac624..95a9247 100644 --- a/.clang-format +++ b/.clang-format @@ -110,4 +110,4 @@ SpacesInParentheses: false SpacesInSquareBrackets: false Standard: Cpp11 TabWidth: 8 -UseTab: Never +UseTab: Never \ No newline at end of file From 1c71de1095802b392c07a0983176e7ef42c000dd Mon Sep 17 00:00:00 2001 From: Imtiaz Ahmed Date: Wed, 4 Mar 2020 10:22:02 -0700 Subject: [PATCH 15/18] fix: clang-format file --- .clang-format | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.clang-format b/.clang-format index 95a9247..5281c9f 100644 --- a/.clang-format +++ b/.clang-format @@ -110,4 +110,5 @@ SpacesInParentheses: false SpacesInSquareBrackets: false Standard: Cpp11 TabWidth: 8 -UseTab: Never \ No newline at end of file +UseTab: Never +... \ No newline at end of file From 33cd7dec0f48eda5e7a8c1483cf4e9a4ef27926c Mon Sep 17 00:00:00 2001 From: Imtiaz Ahmed Date: Wed, 4 Mar 2020 10:22:17 -0700 Subject: [PATCH 16/18] fix: clang-format file --- .clang-format | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.clang-format b/.clang-format index 5281c9f..4b76204 100644 --- a/.clang-format +++ b/.clang-format @@ -111,4 +111,4 @@ SpacesInSquareBrackets: false Standard: Cpp11 TabWidth: 8 UseTab: Never -... \ No newline at end of file +... From 37fe71680dde9692c743a373cfd6adfc8b66a0cf Mon Sep 17 00:00:00 2001 From: Imtiaz Ahmed Date: Wed, 4 Mar 2020 10:27:40 -0700 Subject: [PATCH 17/18] docs: readme updated --- src/PalindromeNumber/README.md | 12 ++++++------ src/PalindromeNumber/Solution.cpp | 1 - 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/PalindromeNumber/README.md b/src/PalindromeNumber/README.md index a167b85..5335119 100644 --- a/src/PalindromeNumber/README.md +++ b/src/PalindromeNumber/README.md @@ -15,18 +15,18 @@ Details of the the algorithm for the solution is as follows: 1. If it's a single digit, then it's a Palindrome Number. 2. Ignore any negative integers. 3. For all other types of integers, pop each digit and store them in a vector in order. -4. Compare the `(n + i)th` integer with `(vector.size() - 1 - i)th` integer. -5. If this comparisos fails (i.e. `comparison == false`) return false. -6. Else continue the comparisons until `i` reaches the middle of the vector. If no `false` was return before, it means all the comparisons were `true` and therefore, the integer is a palindrome. +4. Compare the **(n + i)th** integer with **(vector.size() - 1 - i)th** integer. +5. If this comparisos fails (i.e. **comparison == false**) return **false**. +6. Else continue the comparisons until **i** reaches the middle of the vector. If no **false** was return before, it means all the comparisons were **true** and therefore, the integer is a palindrome. ### Complexity Analysis -* Time Complexity: `O(log⁡(n))` -* Space Complexity: `O(log⁡(n))` +* Time Complexity: **O(log⁡(n))** +* Space Complexity: **O(log⁡(n))** ### AC Result -`11509 / 11509 test cases passed` +**11509 / 11509 test cases passed** | Status | Runtime | Memory | |--------|---------|--------| diff --git a/src/PalindromeNumber/Solution.cpp b/src/PalindromeNumber/Solution.cpp index 19b7786..fd1b07e 100644 --- a/src/PalindromeNumber/Solution.cpp +++ b/src/PalindromeNumber/Solution.cpp @@ -52,6 +52,5 @@ int main() { test("Test case: ", s.isPalindrome(0), true); test("Test case: ", s.isPalindrome(10022001), true); test("Test case: ", s.isPalindrome(1001), true); - return 0; } From 0469310699620669ffe35aaf3466d49c2270cd9a Mon Sep 17 00:00:00 2001 From: Imtiaz Ahmed Date: Wed, 4 Mar 2020 10:29:15 -0700 Subject: [PATCH 18/18] docs: readme updated --- src/PalindromeNumber/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/PalindromeNumber/README.md b/src/PalindromeNumber/README.md index 5335119..36cf024 100644 --- a/src/PalindromeNumber/README.md +++ b/src/PalindromeNumber/README.md @@ -26,7 +26,7 @@ Details of the the algorithm for the solution is as follows: ### AC Result -**11509 / 11509 test cases passed** +Test case result: **11509 / 11509 test cases passed** | Status | Runtime | Memory | |--------|---------|--------|