ZeroDivisionError: integer division or modulo by zero


  • 0
    A

    the problem is "convert("PAYPALISHIRING", 3) should return "PAHNAPLSIIGYIR"."
    my solution is:

    class Solution:
    # @return a string
    def convert(self, s, nRows):
    str1 = ""
    str2 = ""
    str3 = ""
    str_list = list(s)
    for i in range(len(s)):
    if (i+1)%(nRows+1)==1:
    str1 = str1 + str_list[i]
    elif (i+1)%(nRows-1)==0:
    str2 = str2 + str_list[i]
    else:
    str3 = str3 + str_list[i]
    result = str1 + str2 + str3
    return result

    do it in my own system, i have got a right answer, but in OJ, there is a error:
    Submission Result: Runtime Error

     Runtime Error Message:	Line 11: ZeroDivisionError: integer division or modulo by zero
     Last executed input:	"AB", 1
    

    so i need help.


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.