feat: PalindromeNumber Solution Added#21
feat: PalindromeNumber Solution Added#21tiazahmd wants to merge 21 commits intoXFreeCoder:masterfrom
Conversation
MrHeer
left a comment
There was a problem hiding this comment.
- test code with
Test.h - update
README.md - format code with
clang-format - check markdown documentions with
markdownlint
Co-Authored-By: He Linming <hlm52pk@163.com>
|
All of the following requested changes are made:
|
|
The following changes have been made to the new commit:
|
|
@tiazahmd Can you help update https://github.com/XFreeCoder/LeetCode/blob/master/README.md Please reset |
|
Updated master |
|
I think if you could define that a number,xr, which read forward, equal to x reading backward,you will omit vector.And when xr is equal to x,x is a Palindrome Number. |
|
I will be out of town until Tuesday. I’ll make the suggested changes once I’m back. |
|
Made suggested changes. I couldn't get @Zhongnibug 's solution yet. Let me know if you guys still want me to work on that, or if the current solution suffices. |
| } | ||
|
|
||
| return false; | ||
| }; |
| 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; |
There was a problem hiding this comment.
@tiazahmd Do you think this is okay, I have tested AC on leetcode.
| 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; | |
| for (int i = 0; i < vec.size() / 2; i++) { | |
| if (vec[i] != vec[vec.size() - 1 - i]) | |
| return false; | |
| } | |
| return true; | |
| } else { | |
| return false; | |
| } |
Your solution is okey, but @Zhongnibug 's solution is better. Of course, for the best code, if you want to continue to optimize, you can refer to the official solution |
| 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); |
There was a problem hiding this comment.
| 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); | |
| test("Test case 1", s.isPalindrome(121), true); | |
| test("Test case 2", s.isPalindrome(120), false); | |
| test("Test case 3", s.isPalindrome(-121), false); | |
| test("Test case 4", s.isPalindrome(11), true); | |
| test("Test case 5", s.isPalindrome(9), true); | |
| test("Test case 6", s.isPalindrome(0), true); | |
| test("Test case 7", s.isPalindrome(10022001), true); | |
| test("Test case 8", s.isPalindrome(1001), true); |
No problem. Is there something I have to do to finish this? |
|
@tiazahmd I hope you can adopt my suggestion. |
Left space and complexity analysis as to-do since I don't know how to do them yet.
View rendered src/PalindromeNumber/README.md