Leetcode Algo Day6 | Hashtable Part1

Problem: 242. Valid Anagram

Time: 10min

Method: hashtable -  list

Reflection: To be a valid anagram, each letter can only be used once, so need a hashtable to count the letters. Set() does not work.

Time complexity: O(N)

Space complexity: O(1)

Problem: 349. Intersection of Two Arrays

Time: 2min

Method: hashtable - set

Reflection: set() returns unordered unique elements. Set is easy to implement, but more cost of space and time.

Time complexity: O(N+M)

Space complexity: O(N)

Problem: 202. Happy Number

Time: 

Method: hashtable -  list

Reflection: Hashtable is used to detect cycle. divmod() to get both divident and mode. After each loop, reset n = ssq.

Time complexity: O(logN)

Space complexity: O(logN)

Problem: 1. Two Sum

Time: 5min

Method: hashtable -  dict

Reflection: Quesiton prompt mentions exactly one solution. So can use hashtable to find the target pair by selecting from previously iterated elements in linear time.

Time complexity: O(N)

Space complexity: O(N)

相关推荐

  1. <span style='color:red;'>1</span>.<span style='color:red;'>6</span>数组

    1.6数组

    2024-03-16 16:42:04      20 阅读
  2. ES6基础1

    2024-03-16 16:42:04       18 阅读
  3. 2.<span style='color:red;'>1</span>.<span style='color:red;'>6</span> VTP

    2.1.6 VTP

    2024-03-16 16:42:04      10 阅读
  4. MIT 6.824 练习1

    2024-03-16 16:42:04       39 阅读
  5. 6.1 指针的认识

    2024-03-16 16:42:04       37 阅读
  6. StarRocks-3.1.6升级

    2024-03-16 16:42:04       25 阅读

最近更新

  1. TCP协议是安全的吗?

    2024-03-16 16:42:04       16 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2024-03-16 16:42:04       16 阅读
  3. 【Python教程】压缩PDF文件大小

    2024-03-16 16:42:04       15 阅读
  4. 通过文章id递归查询所有评论(xml)

    2024-03-16 16:42:04       18 阅读

热门阅读

  1. 使用vue3 开发H5 ,需要注意的部分点

    2024-03-16 16:42:04       20 阅读
  2. AcWing 4261. 孤独的照片(每日一题)

    2024-03-16 16:42:04       27 阅读
  3. 机器学习模型—Gradient Boosting

    2024-03-16 16:42:04       20 阅读
  4. 堆的建立与排序

    2024-03-16 16:42:04       17 阅读
  5. http的body格式

    2024-03-16 16:42:04       15 阅读