[LeetCode] Ransom Note

  • 时间:
  • 浏览:1
  • 来源:5分11选5APP下载_5分11选5APP官方

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 150ms.

This version is much faster, about 13ms.

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.