随笔分类 -  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 阅读全文
posted @ 2019-12-01 16:46 PirateLHX 阅读(145) 评论(0) 推荐(0)
摘要:class Solution(object): def threeSum(self, nums): """ :type nums: List[int] :rtype: List[List[int]] """ length=len(nums) nums=sorted(nums) ... 阅读全文
posted @ 2018-01-07 20:49 PirateLHX 阅读(110) 评论(0) 推荐(0)
摘要:class Solution(object): def maxArea(self, height): """ :type height: List[int] :rtype: int """ length=len(height) left=0 right=length-1 ... 阅读全文
posted @ 2018-01-07 16:14 PirateLHX 阅读(127) 评论(0) 推荐(0)
摘要: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... 阅读全文
posted @ 2017-12-30 20:59 PirateLHX 阅读(121) 评论(0) 推荐(0)
摘要:class Solution(object): def deleteDuplicates(self, head): """ :type head: ListNode :rtype: ListNode """ tmp=head while tmp: while tmp.n... 阅读全文
posted @ 2017-12-30 20:29 PirateLHX 阅读(106) 评论(0) 推荐(0)
摘要: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 阅读全文
posted @ 2017-12-30 20:08 PirateLHX 阅读(146) 评论(0) 推荐(0)
摘要:class Solution(object): def lengthOfLastWord(self, s): """ :type s: str :rtype: int """ res=s.split() if len(res)!=0: return len(res[-1... 阅读全文
posted @ 2017-12-23 19:00 PirateLHX 阅读(102) 评论(0) 推荐(0)
摘要:class Solution(object): def countAndSay(self, n): """ :type n: int :rtype: str """ s=[] for i in range(n): if i==0: s.a... 阅读全文
posted @ 2017-12-18 09:43 PirateLHX 阅读(120) 评论(0) 推荐(0)
摘要:class Solution(object): def searchInsert(self, nums, target): """ :type nums: List[int] :type target: int :rtype: int """ if target in nums: ... 阅读全文
posted @ 2017-12-17 16:06 PirateLHX 阅读(111) 评论(0) 推荐(0)
摘要:class Solution(object): def strStr(self, haystack, needle): """ :type haystack: str :type needle: str :rtype: int """ return haystack.find(needle) ... 阅读全文
posted @ 2017-12-17 16:00 PirateLHX 阅读(77) 评论(0) 推荐(0)
摘要:class Solution(object): def removeElement(self, nums, val): """ :type nums: List[int] :type val: int :rtype: int """ if not nums: retur... 阅读全文
posted @ 2017-12-17 15:24 PirateLHX 阅读(83) 评论(0) 推荐(0)
摘要:class Solution(object): def removeDuplicates(self, nums): """ :type nums: List[int] :rtype: int """ if not nums: return 0 flag... 阅读全文
posted @ 2017-12-17 15:13 PirateLHX 阅读(93) 评论(0) 推荐(0)
摘要:class Solution(object): def isValid(self, s): """ :type s: str :rtype: bool """ l=[] candidate=['(',')','{','}','[',']'] d={'(':')','{':'}'... 阅读全文
posted @ 2017-12-16 16:18 PirateLHX 阅读(131) 评论(0) 推荐(0)
摘要:class Solution(object): def longestCommonPrefix(self, strs): """ :type strs: List[str] :rtype: str """ if not strs: return "" for i,le... 阅读全文
posted @ 2017-12-16 15:00 PirateLHX 阅读(145) 评论(0) 推荐(0)
摘要: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 ... 阅读全文
posted @ 2017-12-16 14:15 PirateLHX 阅读(150) 评论(0) 推荐(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... 阅读全文
posted @ 2017-12-14 20:30 PirateLHX 阅读(153) 评论(0) 推荐(0)
摘要: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... 阅读全文
posted @ 2017-12-03 21:08 PirateLHX 阅读(164) 评论(0) 推荐(0)
摘要: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... 阅读全文
posted @ 2017-12-03 20:22 PirateLHX 阅读(118) 评论(0) 推荐(0)
摘要:class Solution { public: string convert(string s, int numRows) { if(numRows==1) return s; else { int len=s.size(); int count=0; ... 阅读全文
posted @ 2017-12-03 19:53 PirateLHX 阅读(130) 评论(0) 推荐(0)
摘要:class Solution { public: string longestPalindrome(string s) { int len=s.size(); int left,right; int begin=0,maxlen=0; if(len=0&&rightmaxlen) { ... 阅读全文
posted @ 2017-11-25 19:11 PirateLHX 阅读(132) 评论(0) 推荐(0)