随笔分类 - LeedCode
摘要:Longest Palindromic Substring Given a string s, find the longest palindromic substring in s. You may assume that the maximum length of s is 1000. Exam
阅读全文
摘要:class Solution(object): def threeSum(self, nums): """ :type nums: List[int] :rtype: List[List[int]] """ length=len(nums) nums=sorted(nums) ...
阅读全文
摘要:class Solution(object): def maxArea(self, height): """ :type height: List[int] :rtype: int """ length=len(height) left=0 right=length-1 ...
阅读全文
摘要:class Solution(object): def merge(self, nums1, m, nums2, n): """ :type nums1: List[int] :type m: int :type nums2: List[int] :type n: int :rtype: vo...
阅读全文
摘要:class Solution(object): def deleteDuplicates(self, head): """ :type head: ListNode :rtype: ListNode """ tmp=head while tmp: while tmp.n...
阅读全文
摘要:Description You are climbing a stair case. It takes n steps to reach to the top. Each time you can either climb 1 or 2 steps. In how many distinct way
阅读全文
摘要:class Solution(object): def lengthOfLastWord(self, s): """ :type s: str :rtype: int """ res=s.split() if len(res)!=0: return len(res[-1...
阅读全文
摘要:class Solution(object): def countAndSay(self, n): """ :type n: int :rtype: str """ s=[] for i in range(n): if i==0: s.a...
阅读全文
摘要:class Solution(object): def searchInsert(self, nums, target): """ :type nums: List[int] :type target: int :rtype: int """ if target in nums: ...
阅读全文
摘要:class Solution(object): def strStr(self, haystack, needle): """ :type haystack: str :type needle: str :rtype: int """ return haystack.find(needle) ...
阅读全文
摘要:class Solution(object): def removeElement(self, nums, val): """ :type nums: List[int] :type val: int :rtype: int """ if not nums: retur...
阅读全文
摘要:class Solution(object): def removeDuplicates(self, nums): """ :type nums: List[int] :rtype: int """ if not nums: return 0 flag...
阅读全文
摘要:class Solution(object): def isValid(self, s): """ :type s: str :rtype: bool """ l=[] candidate=['(',')','{','}','[',']'] d={'(':')','{':'}'...
阅读全文
摘要:class Solution(object): def longestCommonPrefix(self, strs): """ :type strs: List[str] :rtype: str """ if not strs: return "" for i,le...
阅读全文
摘要:class Solution(object): def romanToInt(self, s): """ :type s: str :rtype: int """ d={"I":1,"V":5,"X":10,"L":50,"C":100,"D":500,"M":1000} sum=0 ...
阅读全文
摘要:class Solution { public: bool isPalindrome(int x) { vector tmp; int y; if(x<0) return false; y=x; cout<<y<<endl; int count=0; while(y!=0) { tmp.pus...
阅读全文
摘要:class Solution { public: int myAtoi(string str) { if (str.empty()) return 0; int sign = 1, base = 0, i = 0, n = str.size(); while (i = '0' && str[i] INT_MAX / 10 || (base...
阅读全文
摘要:class Solution { public: int reverse(int x) { long long res = 0; while (x != 0) { res = 10 * res + x % 10; x /= 10; } return (res > INT_MAX...
阅读全文
摘要:class Solution { public: string convert(string s, int numRows) { if(numRows==1) return s; else { int len=s.size(); int count=0; ...
阅读全文
摘要:class Solution { public: string longestPalindrome(string s) { int len=s.size(); int left,right; int begin=0,maxlen=0; if(len=0&&rightmaxlen) { ...
阅读全文

浙公网安备 33010602011771号