LeetCode 520: Detect Capital (Ruby)
bengineer

bengineer @bengineer52

About: I'm always a student

Location:
Brazil
Joined:
Aug 21, 2020

LeetCode 520: Detect Capital (Ruby)

Publish Date: Feb 21 '21
0 0

Description: https://leetcode.com/problems/detect-capital/

Solution:

def detect_capital_use(word)
    (word == word.downcase) ||
    (word == word.upcase) ||
    (word == word.downcase.capitalize)
end
Enter fullscreen mode Exit fullscreen mode

Explanation:

1- Check if the word is the same after converting it all to downcase.

1.2- Check if the word is the same after converting it all to upcase.

1.3- Check if the word is the same after converting it all to downcase and then converting the first character to upcase.

Comments 0 total

    Add comment