LoginSignup
0
0

More than 5 years have passed since last update.

Udacity Palindromesの私の解答とメモ

Last updated at Posted at 2018-09-19

Udacityでの学習でのメモとして残したいと思います。たびたびこういったことをやろうと思います。たとえ問題に正解したとしてももっといい方法はあったりしますし。

私の解答

qiita.rb
def is_palindrome(s):
    if s[0] == s[-1] and s[1] == s[-2]:
        return True
    elif s == '':
        return True
    else:
        return False

Udacityの先生の解答

qiita.rb
def is_palindrome(s):
  if s == '':
        return True
    else:
       if s[0] == s[-1]:
         return  is_palindrome(s[1:-1])
         else:
            return  False
0
0
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0