![](https://img-blog.csdnimg.cn/20201014180756928.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
python自用笔记
划水的tjy
这个作者很懒,什么都没留下…
展开
-
整数转罗马数字-暴力哈希表解法
罗马数字包含以下七种字符:I,V,X,L,C,D和M。字符 数值I 1V 5X 10L 50C 100D 500M 1000例如, 罗马数字 2 写做II,即为两个并列的 1。12 写做XII,即为X+II。 27 写做XXVII, 即为XX+V+II。...原创 2021-11-25 08:40:39 · 191 阅读 · 0 评论 -
移除元素,暴力解,指针解
给你一个数组 nums和一个值 val,你需要 原地 移除所有数值等于val的元素,并返回移除后数组的新长度。不要使用额外的数组空间,你必须仅使用 O(1) 额外空间并 原地 修改输入数组。元素的顺序可以改变。你不需要考虑数组中超出新长度后面的元素。来源:力扣(LeetCode)链接:https://leetcode-cn.com/problems/remove-elementclassSolution: #第一想法,很复杂,暴力解defremoveElement(...原创 2021-11-23 19:12:04 · 308 阅读 · 0 评论 -
统计一个圆中点的数目 函数内置函数,及 enumerate()
题目来源:力扣(LeetCode)链接:https://leetcode-cn.com/problems/queries-on-number-of-points-inside-a-circle著作权归领扣网络所有。商业转载请联系官方授权,非商业转载请注明出处。题目强解classSolution:defcountPoints(self,points:[[int]],queries:[[int]])->[int]:listx=[]...原创 2021-11-09 19:44:10 · 3748 阅读 · 0 评论 -
python高度检查器 list中复制copy() 排列sort ()方法运用
给出一组排练高度heights列如[1,2,4,2,5,2]排列不同设定一组预计高度expeceted(按低到高排)[1,2,2,2,4,5]检查两组列表对应位置是否有误,输出一共有几个错误classSolution:defheightChecker(self,heights:[int])->int:expected=heights.copy()#复制列表num=0expected.sort()#排序...原创 2021-11-09 19:32:10 · 544 阅读 · 0 评论 -
string转list split()函数运用
简单题目输出字符串最后一个单词的长度,单词前后可能有空格干扰函数写法class Solution: def lengthOfLastWord(self, s: str) -> int: b=s.split(' ')#转换为列表 s=len(b)+1#提供一个循环长度,防止出现'a '情况 for i in range(s): last_word = b.pop() if last_word.原创 2021-11-09 16:36:45 · 403 阅读 · 0 评论 -
python while 语句 基础认知
code 正确输入 输出Hello useer错误输入几次以下,输出code is wrong , re-enter the code错误输入达到几次 输出The code is incorrecta=1while a<= 2 : code = input("code:") if code == "0620": print("Hello useer") break elif a == 2: b...原创 2021-10-27 22:40:21 · 73 阅读 · 0 评论 -
if-elif-else 基础
杀死外星人颜色,打死绿色加5分,打死其他不加分,和错误颜色显示错误alien_colorlist = ["green","red","yellow"]print("you kill alien color:" ,alien_colorlist)alien_color = input("kill alien_color is :")if alien_color == "green": print("加5分")elif alien_color == "red" or alien_color .原创 2021-10-27 10:28:57 · 133 阅读 · 0 评论