1740954205-344-reverse-string

Question Description

problem link

solution video link

Thought Process

nice this is an easy problem, good for getting used to go syntax

In Go, you specify the type for a variable when you need to explicitly declare its type. However, Go also supports type inference, where the type is automatically determined based on the assigned value. Here are some guidelines:

  1. Explicit Type Declaration: Use this when you want to specify the type explicitly.

    var name string
    var age int
    
  2. Type Inference: Use this when the type can be inferred from the assigned value.

    name := "John"
    age := 30
    

Code

package main

import "fmt"

func reverseString(s []byte) {
	l, r := 0, len(s)-1

	for l < r {
		s[l], s[r] = s[r], s[l]
		l++
		r--
	}
}

Time/Space Complexity

Time: \( O(n) \)

Space: \( O(1) \)