📣 黑五价提前开抢|VIP一年通行证5折,蓝莓、Offer多多同步特惠
楼主: matsuko
跳转到指定楼层
上一主题 下一主题
收起左侧

[Leetcode] 小白转码Leetcode 错题本

🔗
 楼主| matsuko 2026-11-10 08:22:39 | 只看该作者
全局:
怎么把string变成int?
int ()

decode_int = int("".join(temp_int[::-1]))
# decode string
回复

使用道具 举报

🔗
 楼主| matsuko 2026-11-10 09:32:43 | 只看该作者
全局:
dictionary[key] = value !!!
回复

使用道具 举报

🔗
 楼主| matsuko 2026-11-10 10:07:18 | 只看该作者
全局:
Hash/Dict 支持的key类型(hashable):
int, float, str, bool. ❌list
tuple (if everything inside is hashable) ❌dict
frozenset

A dict stores each key in a bucket chosen by hash(key). Later, when you look up the key, Python hashes it again to find that bucket. If the key could change after insertion, its hash would change, Python would look in the wrong bucket, and the entry would effectively be lost. So Python only allows keys whose hash can’t change.

#49. Group Anagrams
回复

使用道具 举报

🔗
 楼主| matsuko 2026-11-10 10:54:52 | 只看该作者
全局:
Hash Table
key Is Unique, value Can Repeat

Every index in an array is unique. Your array can't have two index 0s. As for what elements you store in it, that's up to you. Nobody cares.
回复

使用道具 举报

🔗
 楼主| matsuko 2026-11-10 11:13:59 | 只看该作者
全局:
sorted(s) gives a list, which can’t be a key. sorted("eat") returns ['a','e','t'], and lists aren’t hashable. Turn it into a string or tuple first:
key = "".join(sorted(s))   # "aet"
回复

使用道具 举报

🔗
 楼主| matsuko 2026-11-10 11:21:43 | 只看该作者
全局:
# 49. Group Anagrams
回复

使用道具 举报

🔗
 楼主| matsuko 2026-11-10 17:51:24 | 只看该作者
全局:
preMap = {i: [] for i in range(numCourses)}
# → {0: [], 1: [], 2: [], 3: []}
回复

使用道具 举报

🔗
duochuankuzi 2026-11-10 22:47:53 | 只看该作者
💯 2
全局:
鼓励一下。
就是要多写。
想想LLM咋训练的。就是多强化正确的写法,后面遇到相似的情况不用思考就直接写出来,把珍贵的思考带宽放在真正需要的地方。
LC200题之后回头看之前的自己会更有动力的
回复

使用道具 举报

🔗
 楼主| matsuko 2026-11-11 02:23:05 | 只看该作者
全局:
duochuankuzi 发表于 2026-11-10 06:47:53
鼓励一下。
就是要多写。
想想LLM咋训练的。就是多强化正确的写法,后面遇到相似的情况不用思考就直接写出来,把珍贵的思考带宽放在真正需要的地方。
谢谢鼓励!
回复

使用道具 举报

🔗
 楼主| matsuko 2026-11-11 08:05:34 | 只看该作者
全局:
怎么让hashmap添加key/value pair value是一个计数的情况下
如果已经在hashmap里,val/counter+1;不在就添加:

       preF[sum] = preF.get(sum, 0) + 1
─────────┬───────  ─┬─
            current count (0 if new)            add one

# Subarray Sum Equals K
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册账号
隐私提醒:
  • ☑ 禁止发布广告,拉群,贴个人联系方式:找人请去🔗同学同事飞友,拉群请去🔗拉群结伴,广告请去🔗跳蚤市场,和 🔗租房广告|找室友
  • ☑ 论坛内容在发帖 30 分钟内可以编辑,过后则不能删帖。为防止被骚扰甚至人肉,不要公开留微信等联系方式,如有需求请以论坛私信方式发送。
  • ☑ 干货版块可免费使用 🔗超级匿名:面经(美国面经、中国面经、数科面经、PM面经),抖包袱(美国、中国)和录取汇报、定位选校版
  • ☑ 查阅全站 🔗各种匿名方法

本版积分规则

>
快速回复 返回顶部 返回列表