Skip to content
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

Val - Edges - Integer Palindrome Check #14

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion lib/integer_palindrome_check.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,20 @@
# Returns true if the input positive integer number forms a palindrome. Returns false otherwise.
def is_palindrome(number)
raise NotImplementedError
return false if number.nil?

original = number
reverse = 0

while number > 0
last_digit = number % 10
reverse = reverse * 10 + last_digit
number = number / 10
end

return original == reverse
end

# Time complexity: linear
# Given a number of n digits, the method has a time complexity of O(n). The number of digits is directly proportionate to the the number of times the loop executes.
# Space complexity: constant
# No matter the value of n, the method will require the same amount of memory.