Trick question: O(n) Go string-manip only


  • 0
    A
    func optimalDivision(nums []int) string {
        numStrs := make([]string, len(nums))
        for i, n := range nums {
            numStrs[i] = strconv.Itoa(n)
        }
        
        if len(nums) <= 2 {
            return strings.Join(numStrs, `/`)
        }
        return fmt.Sprintf("%s/(%s)", numStrs[0], strings.Join(numStrs[1:], `/`))
    }
    

Log in to reply
 

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