Wrong test case for GOlang


  • 0
    D

    Below is my code and submission details. I don't know why, but it looks have a some problem in judge system

    0_1476906942757_3CF8EE58-9642-4AD8-8843-EA8EB6D0B83B.png

    func myAtoi(str string) int {
    	if len(str) == 0 {
    		return 0
    	}
    	num := 0
    	idx := 0
    	prefix := 1
    	bs := []byte(str)
    
        for idx < len(str) && (bs[idx] < '0' || bs[idx]> '9') && bs[idx] != '-'  && bs[idx] != '+'  {
    		idx++
    	}
    	
    	if idx >= len(str){
    	    return 0
    	}
    	
    	if bs[idx] == '-' {
    		prefix = -1
    		idx++
    	}else if bs[idx] == '+' {
    		idx++
    	}
    	
    	for idx < len(str) && '0' <= bs[idx] && bs[idx] <= '9' {
    		num *= 10
    		num += int(bs[idx] - '0')
    		idx++
    	}
    
    	return prefix * num
    }
    

Log in to reply
 

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