6. ZigZag Conversion Go语言

go 语言

func convert(s string, numRows int) string {
    
    len_s := strings.Count(s,"") - 1
    
    var i,j int
    var str string = ""
    
    if numRows == 1 {
        return s
    }

    for i = 0; i < numRows; i++{
        if i == 0 || i == numRows - 1{
            for j = i;j < len_s; j += (numRows - 1) * 2{
                str += s[j:j+1]
            } 
        }else{
            var t int
            for j = i;j < len_s; j += (numRows - 1) * 2{
                str += s[j:j+1]
                t = j + (numRows - i - 1) * 2
                if t < len_s {
                    str += s[t:t+1]
                }
                
            }
        }
        
    }
    return str
}

猜你喜欢

转载自blog.csdn.net/dyd961121/article/details/81198121
今日推荐