Re: [閒聊] 每日leetcode

看板Marginalman作者 (smart0eddie)時間1年前 (2024/08/01 13:01), 編輯推噓2(203)
留言5則, 3人參與, 1年前最新討論串612/1550 (看更多)
2024-08-01 2678. Number of Senior Citizens You are given a 0-indexed array of strings details. Each element of details provides information about a given passenger compressed into a string of length 15. The system is such that: The first ten characters consist of the phone number of passengers. The next character denotes the gender of the person. The following two characters are used to indicate the age of the person. The last two characters determine the seat allotted to that person. Return the number of passengers who are strictly more than 60 years old. 靠北 八月了 終於有一題我不用抄解答的了 class Solution { public: int countSeniors(vector<string>& details) { int count = 0; for (auto s : details) { char age1 = s[11]; char age2 = s[12]; if (age1 > '6') { count++; } else if (age1 == '6' && age2 > '0') { count++; } } return count; } }; 慢死 應該用 sub string 轉 int -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 73.173.211.221 (美國) ※ 文章網址: https://www.ptt.cc/bbs/Marginalman/M.1722488518.A.5D1.html

08/01 13:03, 1年前 , 1F
我會把年齡轉成數字後一次判讀
08/01 13:03, 1F

08/01 13:03, 1年前 , 2F
好像沒差多少速度 但你好醜
08/01 13:03, 2F

08/01 13:03, 1年前 , 3F
對不起
08/01 13:03, 3F

08/01 13:03, 1年前 , 4F
大師
08/01 13:03, 4F

08/01 20:00, 1年前 , 5F
大師
08/01 20:00, 5F
文章代碼(AID): #1cgnR6NH (Marginalman)
討論串 (同標題文章)
文章代碼(AID): #1cgnR6NH (Marginalman)