{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "## Number 520" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "https://leetcode.com/problems/detect-capital" ] }, { "cell_type": "code", "execution_count": 11, "metadata": {}, "outputs": [], "source": [ "class Solution:\n", " def detectCapitalUse(self, word: str) -> bool:\n", " if all([ord(x) >= 65 and ord(x) <= ord('Z') for x in word]):\n", " return True\n", " if ord(word[0]) >= 65 and ord(word[0]) <= ord('Z') and all([ord(x) < 65 or ord(x) > ord('Z') for x in word[1:]]):\n", " return True\n", " if all([ord(x) < 65 or ord(x) > ord('Z') for x in word]) :\n", " return True\n", " return False" ] }, { "cell_type": "code", "execution_count": 16, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "True\n", "True\n", "False\n" ] } ], "source": [ "a = Solution()\n", "print(a.detectCapitalUse('g'))\n", "print(a.detectCapitalUse('Leetcode'))\n", "print(a.detectCapitalUse('FlaG'))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "While this is fairly plebian a problem on the face of it, where it distinguishes itself in its demand that \"capital\" means that either no letter be capitalized or all of them be capitalized in addition to the normal meaning of what a capitalized word means." ] } ], "metadata": { "interpreter": { "hash": "033d5ea8e9748582193a6d8f975af35153e280c1f566336ac6ff582d76ae2a04" }, "kernelspec": { "display_name": "Python 3.6.8 64-bit", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.6.8" }, "orig_nbformat": 4 }, "nbformat": 4, "nbformat_minor": 2 }