class Solution(object):
def convert(self, s, numRows):
"""
:type s: str
:type numRows: int
:rtype: str
"""
if len(s)!=1 and numRows!=1:
list=[[] for i in range(numRows)]
for i in range(0,len(s)):
j=i%(2*numRows-2)
div=i//(2*numRows-2)
if j in range ...- read more
5. Longest Palindromic Substring
read moreclass 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 ...
3. Longest Substring Without Repeating Characters
read moreclass Solution(object): def lengthOfLongestSubstring(self, s): """ :type s: str :rtype: int """ new="" list=[] i=0 while i<len(s): if s[i] not in new: new+=s[i] i+=1 else: old=new list+=[old] ind=old.index(s[i]) new="" for j in range(ind+1,len(old ...
2. Add Two Numbers
read more# 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 ...
1. Two Sum
read moreclass 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 ...
Download Bird
read moreimport requests from bs4 import BeautifulSoup from urlparse import urljoin import re def generate_url_list(input_url): r = requests.get(input_url) soup = BeautifulSoup(r.content, 'html.parser') page_list = [] for link in soup.select('a > img'): if "org" in link.parent.get("href"): page_list.append(link.parent.get("href")) continue page_list.append("http ...
0. Prime.py
read moreclass 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 ...
20. Valid Parentheses
read moreclass 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 ...
« Page 21 / 21