搜尋此網誌

2026年6月10日星期三

Part II of Python Test

def decodeString(encodedList):
    decodedStr = ''
    for item in encodedList:
        decodedStr = decodedStr + item[0] * item[1]
    return decodedStr

1. Start with an empty string: decodedStr = ''

2. Loop through each (char, count) tuple in encodedList.

3. Multiply the character by its count:

item[0] * item[1]

Example: 'a' * 3 → "aaa".

4. Concatenate to decodedStr.

5. Return the final reconstructed string.

Microsoft Copilot

沒有留言:

發佈留言