Better HN
topnewbestaskshowjobs
Log inSign up

bastiaanus

3 karma · joined Oct 16, 2013 (13y ago) · 2 submissions

Submissions

comment 13y ago · link · parent

I don't know if it is against the rules, my approach was a recursive function.

comment 13y ago · link · parent

I am at the "write a function that reverses a string without creating a new string" question and this is the answer on the site:

  def reverse(str):
    left_ptr = 0
    right_ptr = len(str) - 1
    middle = len(str) / 2
    while left_ptr <= middle:
        # swap
        temp = str[left_ptr]
        str[left_ptr] = str[right_ptr]
        str[right_ptr]= temp
wouldn't this create an infinite loop? You're never incrementing / decrementing left_ptr or right_ptr.