From 559b0f9f620a49eb1cc8aa15fe97d7ff6cd1e9bd Mon Sep 17 00:00:00 2001 From: gameloader Date: Sun, 3 Nov 2024 15:46:43 +0800 Subject: [PATCH] leetcode update --- content/posts/leetcode.md | 87 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) diff --git a/content/posts/leetcode.md b/content/posts/leetcode.md index 5da5331..89fdf97 100644 --- a/content/posts/leetcode.md +++ b/content/posts/leetcode.md @@ -16908,3 +16908,90 @@ public: } }; ``` + +## day239 2024-11-02 + +### 2490. Circular Sentence + +A sentence is a list of words that are separated by a single space with no leading or trailing spaces. + +For example, "Hello World", "HELLO", "hello world hello world" are all sentences. +Words consist of only uppercase and lowercase English letters. Uppercase and lowercase English letters are considered different. + +A sentence is circular if: + +The last character of a word is equal to the first character of the next word. +The last character of the last word is equal to the first character of the first word. +For example, "leetcode exercises sound delightful", "eetcode", "leetcode eats soul" are all circular sentences. However, "Leetcode is cool", "happy Leetcode", "Leetcode" and "I like Leetcode" are not circular sentences. + +Given a string sentence, return true if it is circular. Otherwise, return false. + +![1102pGUOgMp8TmkY](https://testingcf.jsdelivr.net/gh/game-loader/picbase@master/uPic/1102pGUOgMp8TmkY.png) + +### 题解 + +本题是一道简单题,先判断句子的首尾字符是否相同,不同直接返回false。再遍历句子,每当下一个字符为空格时,考虑到题目中明确说明单词和单词之间只有一个空格分隔,则判断当前字符和下下个字符是否相等,不相等直接返回false。遍历完成则返回true。 + +### 代码 + +```cpp +class Solution { +public: + bool isCircularSentence(string sentence) { + if(sentence[0] != sentence[sentence.size()-1]){ + return false; + } + for (int i=0;i