当前位置:网站首页>[leetcode] understanding and usage of map[key]+

[leetcode] understanding and usage of map[key]+

2022-06-12 23:38:00 Python's path to becoming a God

【Leetcode】map[key]++ Understanding and usage of

stay unorder_map in , You can use square brackets to access the value of the key map[key] . It should be noted that , If it's time to key non-existent ,C++ Will automatically create this key, And put map[key] The assignment is 0.

So we can pass map[key]++ To create key And make key Corresponding value +1, This code can be used in Need to count Under the circumstances .

Then there will be a problem ( It was a problem that arose when I first came into contact ): use map[key]++ You can create key, Then use map[key]-- Can I delete key Well ?

verified : No . adopt ++ To create a key , But not through — To delete the key , Delete can only try erase Function to delete the key .

 Insert picture description here

原网站

版权声明
本文为[Python's path to becoming a God]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202280944531398.html

随机推荐