Does the coll[num] will assign a "0" to the key of the first insert "num" automatically?


  • 0
    J

    Does the coll[str2int(s.substr(i,10))] will assign a "0" to the key of the first insert "str2int(s.substr(i,10))" automatically? Then the ++ operation will add the key "0" to "1"?


  • 0

    Yes, you are right. In C++, as you access the map with the [] operator, if the key does not exist it will get added automatically. As for the value, the default initializer of the int type gets invoked - so it will get a value of 0.


Log in to reply
 

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