尋日有啲leetcode bb對defaultdict唔理解,睇睇以下example
我地呢度用普通dictionary {},你run係會出error,因為我地攞個key-value嘅時候,個key暫時唔存在
如果你用defaultdict嘅話,個key唔存在嘅時候佢會當value係1,你可以改返用defaultdict唔用 {} ,再print,研究下個defaultdict點運作
Day 2:繼續dictionary,不過難少少
https://leetcode.com/problems/sum-of-unique-elements/
https://leetcode.com/problems/two-out-of-three/
sum of unique elements應該比較容易,無咩嘢講
two out of three tricky少少,比一個錯誤示範
我地唔可以直接count每一個數出現幾多次,因為我地嘅目標係想知道每一個數係唔係出現喺最少兩個input,而唔係overall出現最少兩次
你用返尋日嘅skill應該有方法做到
呢題最方便應該用set做,不過新手們試下繼續用dictionary先
加油
聽日見