1. 5. Longest Palindromic Substring

    class Solution(object):
        def longestPalindrome(self, s):
            """
            :type s: str
            :rtype: str
            """
            long=""
            temp=""
            i=0
            gap = 2
            gap2=1
    
            if len(s)==1:
                return s
    
            while i < len(s)-gap:
                if s[i] == s[i+gap]:
                    temp=s[i:i+gap+1]
                    ii=i
                    ii-=1
                    gap+=2
    
                    while ...
    read more
  2. 2. Add Two Numbers

    # Definition for singly-linked list.
    class ListNode(object):
        def __init__(self, x):
            self.val = x
            self.next = None
    
    class Solution(object):
        def addTwoNumbers(self, l1, l2):
            """
            :type l1: ListNode
            :type l2: ListNode
            :rtype: ListNode
            """
            head = ListNode(0)
            ptr = head
            carry  = 0
            while True:
                if l1 != None:
                    carry += l1.val
                    l1 = l1 ...
    read more
  3. 1. Two Sum

    class Solution(object):
        def twoSum(self, nums, target):
            """
            :type nums: List[int]
            :type target: int
            :rtype: List[int]
            """
            for i in range(len(nums)):
                for j in range (i+1,len(nums)):
                    if target-nums[i]==nums[j]:
                        return [i,j]
    
    if __name__ == "__main__":
        answer = Solution()
        nums=[2, 7, 11 ...
    read more
  4. 0. Prime.py

    class Solution(object):
        def isPrime(self, integer):
            i=2
            while i<integer:
                if integer%i==0:
                    return False
                else:
                    i+=1
            return True
    
        def printPrime(self,n,m):
            list=[]
            i=n
            while i<=m:
                if self.isPrime(i):
                    list.append(i)
                i+=1
            return list
    
    if __name__ == "__main__":
        n = 100 ...
    read more
  5. 20. Valid Parentheses

    class Solution(object):
        def isValid(self, s):
            """
            :type s: str
            :rtype: bool
            """
    
            list = []
            l=["(","[","{"]
            n=[")","]","}"]
            issy=True
    
            if len(s) == 0:
                return False
    
            i=0
            while i<len(s) and issy:
                 if s[i] in l:
                    list.append(s[i])
                 elif len(list)!=0:
                    firsti=list[-1]
                    if l.index ...
    read more

« Page 21 / 21

blogroll

social