class Solution {
    public boolean wordPattern(String pattern, String str) {
        HashMap<Character,Integer> map1 = new HashMap<>();
        HashMap<String,Integer> map2 = new HashMap<>();
        
        String [] s = str.split(" ");
        if(s.length!=pattern.length()) return false;
        for(int i =0;i<pattern.length();i++)
        {
            char ch = pattern.charAt(i);
            if(!map1.containsKey(ch)) map1.put(ch,i+1);
            if(!map2.containsKey(s[i])) map2.put(s[i],i+1);
            
            int a = map1.get(ch);
            int b = map2.get(s[i]);
                     
            if(a!=b) return false;
        }
        return true;
    }
}

这道题,当值>128时,map.get() != map.get() 会出现错误结果,但不知道为什么

相关文章:

  • 2022-12-23
  • 2021-12-20
  • 2022-01-10
  • 2022-12-23
  • 2021-08-17
  • 2018-05-30
  • 2021-07-23
猜你喜欢
  • 2023-03-22
  • 2022-02-19
  • 2021-09-01
  • 2021-08-26
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案