Golang is strange

in blurt •  3 years ago 

I don't like these syntax - so weird. Performing the operations to array/stack/queue is so unfriendly.

func longestValidParentheses(s string) int {
    var ans = 0
    var st = []int {-1}
    for i, c := range s {
        if c == '(' {
            st = append(st, i)
            continue
        }
        st = st[:len(st)-1]
        if len(st) == 0 {
            st = append(st, i)
        } else {
            var t = i - st[len(st)-1]
            if t > ans {
                ans = t
            }
        }
    }
    return ans
}

1a57c5c227ec904c211657d2f233656.png

^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Thank you for reading ^^^^^^^^^^^^^^^

NEW! Following my Trail (Upvote or/and Downvote)

Follow me for topics of Algorithms, Blockchain and Cloud.
I am @justyy - a Steem Witness
https://steemyy.com

My contributions

Delegation Service

Important Update of Delegation Service!

  • Delegate 1000 to justyy: Link
  • Delegate 5000 to justyy: Link
  • Delegate 10000 to justyy: Link

Support me

If you like my work, please:

  1. Delegate SP: https://steemyy.com/sp-delegate-form/?delegatee=justyy
  2. Vote @justyy as Witness: https://steemyy.com/witness-voting/?witness=justyy&action=approve
  3. Set @justyy as Proxy: https://steemyy.com/witness-voting/?witness=justyy&action=proxy
    Alternatively, you can vote witness or set proxy here: https://steemit.com/~witnesses

Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE BLURT!