LeetCode腾讯精选50题
Day1:今天时间比较赶,粗略写一下吧
1、任务题目:
2、实现代码(一行代码)
class Solution:
def reverseString(self, s: List[str]) -> None:
s.reverse()
3、遇到的问题
(1)def reverseString(self, s: List[str]) -> None: #这句话不能理解self; s: List[str] ; -> None 三个部分
解决:
self的用法 摘自:https://blog.csdn.net/qq_37616069/article/details/79386928这个博主写的很清晰易懂
s: List[str] ; 入参(入参类型)
-> None 返回值
(2)第一次刷leetcode的题。不熟悉其各自变量
class Solution:
def reverseString(self, s: List[str]) -> None:
"""
Do not return anything, modify s in-place instead.
"""
List = input()
List.reverse()
return List
reverseString(List)
#报错NameError: name 'List' is not defined
解决:
(1)s:List就是那个系统已经设置好的列表数组
(2)注意注释里说明,不用return,也不用执行方法。系统会自动执行
4、参考资料
https://blog.csdn.net/qq_37616069/article/details/79386928Python3自定义函数中self用法详解