Why golang solution TLE


  • 0
    W

    I use the same algorithm for Java & Golang, java is accepted with 3ms, but Golang TLE; why?


  • 0
    R

    I have the same problem. Here is my code TLE on 17/th test case:

    Hi @administrators , can you guys take a look? This is the Golang implementation as the top 5 solutions

    func getModifiedArray(length int, updates [][]int) []int {
        
        res := make([]int, length)
        
        for j:=0; j < len(res); j++ {
            res[j] = 0
        }
        
        
        for _, update := range updates {
            value, start, end := update[2], update[0], update[1]
            
            res[start] += value
            
            if end < length - 1 {
                res[end+1] -= value
            }
        }    
        sum := 0
        
        for i:=0; i < length; i++ {
            sum += res[i]
            res[i] = sum
        }
        return res
    }
    

  • 0

    This was just fixed. Golang solution should pass now.


  • 0
    R

    @1337c0d3r Thanks!


Log in to reply
 

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