title: Dynamically sized Array in golang?
body: <p>I would like to know if there is any way by which I can create dynamically sized array to avoid runtime error in the code below.</p>
  
  <p>Error:</p>
  
  <blockquote>
    <p>panic: runtime error: index out of range in Go</p>
  </blockquote>
  
  <p>Code:</p>
  
  <pre class="lang-golang prettyprint-override"><code>/**
   * Definition for singly-linked list.
   * type ListNode struct {
   *     Val int
   *     Next *ListNode
   * }
   */
  func nextLargerNodes(head *ListNode) []int {
  
      var a []int
      var pha int
      hNum := 0
      currNode := head
      pha = 0
      for currNode.Next != nil {
          iter := currNode.Next
          hNum = currNode.Val
          //phb = pha + 1
          for(iter.Next != nil){
              if hNum &lt; iter.Val {
                  hNum = iter.Val
                  break
              } else if hNum == iter.Val{
                  hNum = 0
                  break
              }
  
              iter = iter.Next
          }
          a[pha] = iter.Val
          pha++
          hNum = 0
          currNode = currNode.Next
      }
      return a
  }
  </code></pre>