[LeetCode] Ransom Note

  • 时间:
  • 浏览:0
  • 来源:大发彩神幸运飞艇_大发神彩幸运飞艇官方

In fact, arrays can be used to replace hash maps since the test cases of this problem only contan the 26 English letters. A array-version solution can be found here and is rewritten below.

This code takes about 100ms.

A very typical application of hash maps. Since I am now learning Java, I code in Java. The following code uses toCharArray() and getOrDefault(), which are learnt from this post.

This version is much faster, about 13ms.