跳轉到

Posts

HTB - Responder

閱讀限制

此篇文章有受到作者設定的閱讀限制...

13. Roman to Integer

題目大意

羅馬數字由七個不同的符號表示:IVXLCDM

Symbol       Value
I             1
V             5
X             10
L             50
C             100
D             500
M             1000

例如,2 用羅馬數字寫作 II,就是兩個一加在一起。12 寫作 XII,即 X + II。數字 27 寫作 XXVII,即 XX + V + II

羅馬數字通常從左至右按大小寫成。然而,數字四不寫作 IIII。相反,數字四寫作 IV。因為一在五前面,我們把它減去,這樣就變成了四。同樣的原則也適用於數字九,寫作 IX。有六種情況會使用減法原則:

  • I 可以放在 V(5)和 X(10)之前,來表示 4 和 9。
  • X 可以放在 L(50)和 C(100)之前,來表示 40 和 90。
  • C 可以放在 D(500)和 M(1000)之前,來表示 400 和 900。

給出一個羅馬數字,將其轉換為一個整數。

範例一
Input: s = "III"
Output: 3
Explanation: III = 3.
範例二
Input: s = "LVIII"
Output: 58
Explanation: L = 50, V= 5, III = 3.
範例三
Input: s = "MCMXCIV"
Output: 1994
Explanation: M = 1000, CM = 900, XC = 90 and IV = 4.

題目原文連結

Reverse words

題目大意

完成一個功能,它接受一個字串變數作為參數,將字串中的每個字詞反轉,並保留字串中的所有空格。

範例

"This is an example!" ==> "sihT si na !elpmaxe"
"double  spaces"      ==> "elbuod  secaps"

3. Longest Substring

題目大意

給定一個字串 s,找出其中不包含重複字元的最長子字串長度。

範例一
Input: s = "abcabcbb"
Output: 3
Explanation: The answer is "abc", with the length of 3.
範例二
Input: s = "bbbbb"
Output: 1
Explanation: The answer is "b", with the length of 1.
範例三
Input: s = "pwwkew"
Output: 3
Explanation: The answer is "wke", with the length of 3.
Notice that the answer must be a substring, "pwke" is a subsequence and not a substring.

題目原文連結