HT290WordPattern

来源:互联网 发布:淘宝承接页是什么 编辑:程序博客网 时间:2024/05/22 22:24

思路

  • 一个hashmap
  • 一个hashmap
  • 一个StringArray

易错

  • 一旦用for开始循环,就要想到length==0的情况,尤其是string
  • String should not use == to compare, should use _String.equals()

Some tricks

  • String can be “” but is not null. Should use _String.length() to judge. Be smart to use _String.length() or _Array.length to get rid of corner cases.
  • In HashMap, if you have to judge (containsValue), you may need to exchange the key and value to avoid this

Failed Test Cases

  • Diff Keys but same values
"abba""dog dog dog dog"
  • If too many chars in the pattern, the Index as Value Hash Map method would concur a problem that the length of pattern go beyond the length of Integer. We should use
Objects.equals(oneObject, theOtherObject)
0 0
原创粉丝点击