-
Notifications
You must be signed in to change notification settings - Fork 2
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
feat: PalindromeNumber Solution Added #21
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- test code with
Test.h
- update
README.md
- format code with
clang-format
- check markdown documentions with
markdownlint
Co-Authored-By: He Linming <[email protected]>
All of the following requested changes are made:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you're not update README.md
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; | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
}; | |
} |
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ping @tiazahmd
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@tiazahmd Hello, Is there problem?
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