-
Notifications
You must be signed in to change notification settings - Fork 1
Open
Description
I renamed a couple variables for clarity.
In this code, i += 1 does nothing, because range is an iterator not a literal < check.
def findString(self, n: int) -> int:
'''Find start index of the nth string.
Is aware of the 2nd version code byte.
Args:
n (int): Zero indexed.
Returns:
int: 0, or logs and returns -1 if the string isn't found
within the buffer
'''
if n == 0:
return 1 # first one is automatic
currentStart = 1
stringsFound = 0
# scan over the buffer
for i in range(1, 252):
# checking for an end-of-string mark
if self.data[i] == 0:
# found one - this ends the stringCount string
# if that's the request, return start
if stringsFound == n:
return currentStart
# if not, the _next_ character starts the next string
currentStart = i+1
stringsFound += 1
# special case for the 5th string
if stringsFound == 4:
i += 1
currentStart += 1
# fell out without finding
return 0So I assume I should change it like this:
- for i in range(1, 252):
- i = 1
+ while i < 252:
- then at the end of the loop add
i += 1to continue as the old code would:
+ i += 1?
Metadata
Metadata
Assignees
Labels
No labels