摘要:
class Solution: def maxArea(self, height: List[int]) -> int: # 问题的本质,就是(i-j)*min(List[i],List[j]) # 如果移动长板,那么面积就一定会减小 # 所以在移动的时候,一定是移动短板 # 经典双指针问题 Lef 阅读全文
摘要:
# 逆向循环: >>> ListA = [0, 1, 2, 1, 4, 1, 6, 1, 8, 1] >>> for i in reversed(range(len(ListA))): ... print(i) ... 9 8 7 6 5 4 3 2 1 0 # 正向循环 >>> ListA = [ 阅读全文
摘要:
class Solution: def removeElement(self, nums: List[int], val: int) -> int: while val in nums: nums.remove(val) return len(nums) remove()方法在使用过程中,往往需要结 阅读全文
摘要:
4、使用count()方法 Python count() 方法用于统计字符串里某个字符或子字符串出现的次数。可选参数为在字符串搜索的开始与结束位置。 >>> str='aaabaaaabaaabaaaabaaaabaaaabaaaaba' >>> substr='aaaba' >>> str.cou 阅读全文
摘要:
3、使用index()和rindex(): >>> str = "this is really a string example....wow!!!" >>> substr = "is" >>> print(str.index(substr)) 2 >>> print(str.rindex(subs 阅读全文
摘要:
考察的重点,是Python判断字符串是否包含另一字符串 class Solution: def maxRepeating(self, sequence: str, word: str) -> int: for _i in range(1,100): if word * _i in sequence: 阅读全文
摘要:
一道很基础的题目,核心考点:拼接列表 涉及到的知识点: 1、Python列表拼接的三种方式: List_A+List_B 切片赋值 extend() 2、切片赋值的用法(从无到有进行了学习) 3、extend()返回None的原因 4、三种用法的好坏(耗时、占用内存)(i->最优) 阅读全文
摘要:
问题代码: class Solution(): def getConcatenation(self, nums): print(nums.extend(nums)) A = Solution() A.getConcatenation([1, 2, 3]) 代码最后的回显为: [1, 2, 3] No 阅读全文
摘要:
题解: 采用(1)中相加的方法: class Solution: def getConcatenation(self, nums: List[int]) -> List[int]: return nums+nums 采用(1)中切片赋值的方法: class Solution: def getConc 阅读全文
摘要:
考察的重点,是列表拼接的方法: class Solution: def getConcatenation(self, nums: List[int]) -> List[int]: nums[len(nums):len(nums)]=nums return nums 列表拼接方法: 1、ListA+L 阅读全文
摘要:
1、del语句:del语句->索引 2、方法:pop():pop()->索引 2.1、pop()进阶->pop()在括号中指定元素的索引,即可删除指定元素 # pop()方法删除的是列表的最后一个元素 >>> list1229_new [2, 3, 4, 2, 3, 2] # 首先是打印了一个列表 阅读全文
摘要:
解决办法: ssh-keygen -R 远程服务器IP 阅读全文
摘要:
cp stands for copy. This command is used to copy files or group of files or directory. It creates an exact image of a file on a disk with different fi 阅读全文
摘要:
命名规范推荐 Packages:lower_with_under Modules:lower_with_under Class:CapWords(UpperCamelCase) Exceptions:CapWords Functions:lower_with_under() Global/Class 阅读全文
摘要:
属性 (必须遵守)(规则): 3、公共属性的注释写在属性声明的上方,与声明保持同样的缩进; 行内注释应以#和一个空格作为开始,与后面的文字注释以一个空格隔开; 说明:行内注释的形式是在语句上一行中加注释;行内注释要少用,他们应以#和一个空格作为开始; 格式 (必须遵守)(规则): 4、模块文档字符串 阅读全文
摘要:
注释和文档字符串的原则是:有助于对程序的阅读理解; python没有类型信息,IDE不能帮助提示,如果没有注释,动态语言就很难理解; 注释不宜太多也不能太少,一般建议建议有效注释量(包括文档字符串)应该在20%以上。 撰写好的注释有以下建议: 注释描述必须准确、易懂、简洁,不能有二义性; 避免在注释 阅读全文
摘要:
导入: (必须遵守)(规则): 10、加载模块必须分开,每个模块占一行; 一行只能加载一个模块,但,同一个模块内,多个符号,可以在同一行加载; import 语句有一个变体,可以直接把模块里的名称导入到另一个模块的符号表: >>> from fibo import fib, fib2 >>> fib 阅读全文
摘要:
排版相关: 缩进: (必须遵守)(规则): 1、程序块采用缩进风格编写,缩进的空格数为4个,是业界通用的标准; 2、禁止混用空格(SPACE)和跳格(TAB) 3、新项目必须使用纯空格(SPACE)来代替跳格(TAB) 语句: 4、Python文件必须使用UTF-8编码:Python文件必须使用UT 阅读全文
摘要:
1 ListA=[] 2 ListB=[1] 3 if not ListA: 4 print("List A Empty~") 5 if ListB: 6 print("List B NOT Empty~") 最后的回显为: 1 (PythonVirtualEnv_3100) PS D:\Pytho 阅读全文
摘要:
类型比较的时候 要使用 isinstance(item, str) 不用 type(item) == str 区别在于: type()不会认为子类是一种父类类型; isinstance()会认为子类是一种父类类型; class FOO(): pass class BAR(FOO): pass pri 阅读全文