lower() # return ''.join([ chr(ord(char) + 32) if 65 <= ord(char) <= 90 else char for char in str]) if __name__ == '__main__': """""" s = "LOVELY" print(s) with Timeit(): s1 = Solution1() print(s1.toLowerCase(s)
方案1:DFS classSolution:#@return a booleandefisInterleave(self, s1, s2, s3):iflen(s1)+len(s2) ==len(s3):returnself.DFS(s1,s2,s3)else:returnFalsedefDFS(self,s1,s2,s3):ifnot(s1ands2) :ifs3 == s1+s2:returnTrueelse:returnFalseifs1[0] == s3[0]andself.DFS(s1[1:],s2,s3[1:...
3 python 基础 3.1 数据类型 3.2 Number(数字) 3.3 String(字符串,一个字符也是字符串) 3.4 List(列表)和Tuple(元组) 3.5 set(集合) 3.6 dict(字典) 3.7 其他函数 3.8 迭代器、生成器(节约时间)和匿名函数 3.9 文件读取 3.10 OS 文件/目录方法 3.11 错误和异常 3.12 面向对象 4 二叉树 4.1 基本概念 4.2...
AI代码解释 classSolution:defmyAtoi(self,str:str)->int:returnmax(min(int(*re.findall('^[\+\-]?\d+',str.lstrip())),2**31-1),-2**31)#链接:https://leetcode-cn.com/problems/string-to-integer-atoi/solution/python-1xing-zheng-ze-biao-da-shi-by-knifezhu/ 表现结果: Runtime: 28 ...
classSolution(object):defreverseString(self, s): lst=[]foriinrange(len(s)): lst.append(s[-(i + 1)]) lst=''.join(lst)returnlst Nim GAME Core: Second player only win when total accoumt % 4 = 0 classSolution(object):defcanWinNim(self, n): ...
classSolution{public:voidreverseString(vector<char>&s){char a[]=s;// 错误:这里使用了错误的方式来初始化一个字符数组for(int i=0;i<s.length/2;i++){swap(a[i],s[s.length-1-i]);}returna;// 错误:reverseString() 的返回类型是 void,不应该返回任何值}}; ...
class Solution { public boolean isMatch(String s, String p) { int sRight = s.length(), pRight = p.length(); while (sRight > 0 && pRight > 0 && p.charAt(pRight - 1) != '*') { if (charMatch(s.charAt(sRight - 1), p.charAt(pRight - 1))) { ...
Python:class Solution: def decodeString(self, s: str) -> str: stack = [] for c in s: if c == ']': repeatStr = '' repeatCount = '' while stack and stack[-1] != '[': repeatStr = stack.pop() + repeatStr # pop 掉 "[" stack.pop() ...
对应的 Java 仓库的地址,传送门:https://github.com/liweiwei1419/LeetCode-Solution-Java 说明:现在刷题,尤其是写题解,绝大多数问题都会写两个语言的代码,Java 是我的母语,Python 是我的新欢。 发布在 LeetCode 中文版上的题解配图使用的 PPT,传送门:https://github.com/liweiwei1419/LeetCode-Solution-PPT...