leetcode_136 只出现一次的数字 class Solution(object): def singleNumber(self, nums): """ :type nums: List[int] :rtype: int """ ans = 0 for i in nums: ans ^= i return ans 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 参考文献: https://www.runoob.com/python3/python3-tutorial.ht...
LeetCode 5 Longest Palindromic Substring 问题描述: 解答: 接下来补上manacher算法。 在没了解Manacher之前,我们可以直接暴力枚举,时间复杂度O(n3),也可以用聪明一点的方法,每次枚举一个点,比较它左右距离相同的点是否相同...长度就是该回文串的回文半径我们都知道,中心检测法是依次枚举每一个点的回文半径,取所...
Given a linked list, reverse the nodes of a linked list k at a time and return its modified list. k is a positive integer and is less than or equal to the length of the linked list. If the number of nodes is not a multiple of k then left-out nodes in the end should remain as...
html = urlopen(url)exceptHTTPErrorase:# the page is not found on the server (or there was an error in retrieving it).returnNonetry:# if the server is not found (or the server did not exist),# then html would be a None object, and html.read() would throw an AttributeErrorbs = ...
题目Given a string, find the first non-repeating character in it and return it's index. If it doesn't exist, return -1. Examples: s = "leetcode" return 0. s = "loveleetcode", retur i++ 字符串 原创29天前57阅读yyds干货盘点 ...
packageleetcodeimport"strings"funcreverseWords151(sstring)string{ss:=strings.Fields(s)reverse151(&ss,0,len(ss)-1)returnstrings.Join(ss," ")}funcreverse151(m*[]string,iint,jint){fori<=j{(*m)[i],(*m)[j]=(*m)[j],(*m)[i]i++j--}} ...
这一题比较简单,直接写即可。 参考代码 packageleetcodeimport"strings"// 解法一funcstrStr(haystackstring,needlestring)int{fori:=0;;i++{forj:=0;;j++{ifj==len(needle){returni}ifi+j==len(haystack){return-1}ifneedle[j]!=haystack[i+j]{break}}}// 解法二funcstrStr1(haystackstring,needlestri...
packageleetcodeimport("container/list""fmt""strconv")// 解法一funccalculate(sstring)int{i,stack,result,sign:=0,list.New(),0,1// 记录加减状态fori<len(s){ifs[i]==' '{i++}elseifs[i]<='9'&&s[i]>='0'{// 获取一段数字base,v:=10,int(s[i]-'0')fori+1<len(s)&&s[i+1...
packageleetcodeimport("github.com/halfrost/LeetCode-Go/template")vardir=[][]int{{-1,0},{0,1},{1,0},{0,-1},}// 解法一 并查集funcsolve(board[][]byte){iflen(board)==0{return}m,n:=len(board[0]),len(board)uf:=template.UnionFind{}uf.Init(n*m+1)// 特意多一个特殊点用来标记...
— No, it’s not that simple. Suppose that I change the first digit to an 8, then the number will read 8033 which is not a prime! — I see, being the prime minister you cannot stand having a non-prime number on your door even for a few seconds. — Correct! So I must invent ...