443. String Compression - Day 2/31 Leetcode March Challenge
Vložit
- čas přidán 28. 02. 2023
- Larry solves and analyzes this Leetcode problem as both an interviewer and an interviewee. This is a live recording of a real engineer solving a problem live - no cuts or edits!
Problem: leetcode.com/problems/string-...
Twitch: / larryny
Discord: / discord
Instagram: / larrysomewhere
#leetcode #coding #programming - Věda a technologie
Did you compress okay?
Thanks for the solution!
Good works, man of God.
man you do it very like a player of the gnme for a long time something new people like me had hard time to understand this
You look like Australian Batsman David Warner
Haha, I don't think so but if he's rich maybe!
@@Algorithmist he is rich as hell
import json
class Solution:
def compress(self, chars: List[str]) -> List[str]:
l = len(chars)
res = chars[0]
temp = chars[0]
c = 1
for i in chars[1:]:
if i == temp:
c += 1
else:
if c > 1:
res += str(c)
c = 1
temp = i
res += i
if c > 1:
res += str(c)
mod_res = list(res)
mod1_res = json.dumps(mod_res)
return len(mod1_res)-1
what is wrong with my leetcode 443 solution... I have a problem in returning
try the discord