iT邦幫忙

0

Leetcode 中文。你可能只花一分鐘寫完程式碼,但是比較困難在於閱讀英文題目。

  • 分享至 

  • xImage
  •  

歐氏定理: 「英文文法跟中文是相反的。」
Return true if s is an acronym of words, and false otherwise.
上述英文句字是 Leetcode 題目常出現的句子。
正確能理解成中文,要從 「, 」(逗點)進行分割。

如果 s 是字串acronym,回傳 true

  1. Return true if s is an acronym of words,
    其他就回傳 false.
  2. and false otherwise.

在進行英文句子分割時要分割對,
「, 」(逗點)
of, and 都是重要的分割地方
--程式答案-----------------
2828. Check if a String Is an Acronym of Words
你可能只花一分鐘寫完程式碼,但是比較困難在於閱讀英文題目__________________\

 class Solution {
public:
    bool isAcronym(vector<string> &words, string s) {
        string ws ="";
        for( auto w: words){
            ws += w[0];
        }
        if(ws == s)
            return true;
        else
            return false;
    }
};
  1. Check if a String Is an Acronym of Words

Given an array of strings words and a string s, determine if s is an acronym of words.

The string s is considered an acronym of words if it can be formed by concatenating the first character of each string in words in order. For example, "ab" can be formed from ["apple", "banana"], but it can't be formed from ["bear", "aardvark"].

Return true if s is an acronym of words, and false otherwise.

Example 1:

Input: words = ["alice","bob","charlie"], s = "abc"
Output: true
Explanation: The first character in the words "alice", "bob", and "charlie" are 'a', 'b', and 'c', respectively. Hence, s = "abc" is the acronym.

Example 2:

Input: words = ["an","apple"], s = "a"
Output: false
Explanation: The first character in the words "an" and "apple" are 'a' and 'a', respectively.
The acronym formed by concatenating these characters is "aa".
Hence, s = "a" is not the acronym.

Example 3:

Input: words = ["never","gonna","give","up","on","you"], s = "ngguoy"
Output: true
Explanation: By concatenating the first character of the words in the array, we get the string "ngguoy".
Hence, s = "ngguoy" is the acronym.

Constraints:

1 <= words.length <= 100
1 <= words[i].length <= 10
1 <= s.length <= 100
words[i] and s consist of lowercase English letters.

這篇是我貼在我的Linkedin 裡的文章,一天內有破 150 人觀看,
我應該是寫的不錯,才會有這麼高的人次觀看。
分享給大家。

我想到一個職場故事分享給大家,這是我親身經歷。
有一天,我被主管叫到他個人的辨公室裡,進行一對一的面談。
他說: 「Mr. 歐,我知道你很優秀,但是依照你現在的階段、經歷你要使別人更優秀
其實,我當下聽不懂,但是,我有背起來。
過了幾年,我才理解,原來他講的是「團隊的重要」。
雖然,我是全國競賽第一名,但整個團隊的經營是主管所在意的事情。
所以,我開始寫文章,分享我的經驗,使讀者更優秀。

作者:歐育溙 Billour Ou
Version: 2023111501


圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言