![](https://img-blog.csdnimg.cn/20201014180756925.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
LeetCode
m0_46483236
这个作者很懒,什么都没留下…
展开
-
python 中内置函数ord()返回字符串的ASCII数值
注意如下几点: ord() 函数是 chr() 函数(对于 8 位的 ASCII 字符串)的配对函数,它以一个字符串(Unicode 字符)作为参数,返回对应的 ASCII 数值,或者 Unicode 数值。 应用实例:ord()函数的一个应用场景就是,利用哈希表解决字母异位词问题。利用ord()函数求解每个字母的ASCII数值,再利用每个字母和字母a之间的差值,将26个小写英文字母映射到下标分别为0-25的数组上,数组中存放的是每个字母的数目。例如:......原创 2022-07-05 23:04:51 · 7542 阅读 · 0 评论 -
python 中defaultdict()对字典进行初始化
defaultdict()的作用在于,即使字典中的key不存在,在查找时也会对它的value赋予一个默认值。应用举例: 题目描述: 2. 使用defaultdict(): 参考:https://www.jianshu.com/p/bbd258f99fd3原创 2022-07-04 22:09:33 · 1461 阅读 · 0 评论 -
LeetCode 合并两个有序数组
题目描述: 解题: class Solution(object): def merge(self, nums1, m, nums2, n): """ :type nums1: List[int] :type m: int :type nums2: List[int] :type n: int :rtype: None Do not return anything, modify nu..原创 2022-01-18 21:02:30 · 268 阅读 · 0 评论 -
LeetCode 加一
题目描述:方法1:class Solution(object): def plusOne(self, digits): """ :type digits: List[int] :rtype: List[int] """ num = '' for i in digits: num += str(i) num = int(num) ...原创 2022-01-17 17:37:30 · 84 阅读 · 0 评论 -
python 利用集合set()的唯一性去掉重复元素
1集合和列表的相互转化python中集合用{ }表示,集合中的元素具有唯一性。如 jihe1 = {1, 2, 4, 6} 集合和列表的长度都可以用len()函数获得 集合和列表之间相互转化: liebiao1 = list(jije1) jihe1 = set(liebiao1) 为什么将集合转化成列表? 注意,集合本身不支持索引操作,所以将集合转化为列表是读取集合元素的必要步骤。 为什么将列表转化成集合? 将集合转化成列表,可以对列表元素实现去重操作,可以执行集合操作,实现...原创 2022-01-16 13:51:41 · 739 阅读 · 0 评论 -
罗马数字转整数
解题1:class Solution(object): def romanToInt(self, s): """ :type s: str :rtype: int """ num = 0 i = 0 for t in range(len(s)): if i == len(s): break if...原创 2022-01-13 22:14:33 · 78 阅读 · 0 评论