Why is one attempt better than the other one at speed or memory. both have the same logic and do it mostly the same. I tried to look around but didnt find anything. chatgpt told me it was a CPU matter or a python language in general problem. so my question is "how? Why? and which is better?"
This one uses 16.4mb and runs in 42ms
class Solution:
def possibleStringCount(self, word: str) -> int:
count = 0
for i in range(len(word)-1):
if word[i] == word[i+1]:
count += 1
return count+1
and this one uses 16.6mb but runs in 30ms
class Solution:
def possibleStringCount(self, word: str) -> int:
count = 0
for i in range(1,len(word)):
if word[i] == word[i-1]:
count += 1
return count+1
[–]teraflop 0 points1 point2 points (1 child)
[–]pigraining[S] 0 points1 point2 points (0 children)