Skip to content

Commit c8a6596

Browse files
committed
finish 3 beta
1 parent d663195 commit c8a6596

6 files changed

+74
-0
lines changed

[8 kyu]Object Oriented Piracy.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
class Ship:
2+
def __init__(self, draft, crew):
3+
self.draft = draft
4+
self.crew = crew
5+
6+
def is_worth_it(self):
7+
return self.draft - 1.5 * self.crew >= 20
8+
9+
boat = Ship(21,0)
10+
print(boat.is_worth_it())

[beta]Complete The Pattern #1.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
def pattern(n):
2+
if n < 1:
3+
return ''
4+
res = '1'
5+
for i in range(2,n+1):
6+
res += '\n' + str(i) * i
7+
return res

[beta]Complete The Pattern #2.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
def pattern(n):
2+
string = ''.join([str(i) for i in range (1,n+1)][::-1])
3+
res = ''
4+
for i in range(1,n+1):
5+
res += '\n' if len(res) > 0 else ''
6+
res += string
7+
string = string[:-1] if len(str(i)) == 1 else string[:-2]
8+
return res
9+
10+
11+
12+
for i in (13,):
13+
print(pattern(i))
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
def pattern(n):
2+
string = ''
3+
res = []
4+
for i in range(n,0,-1):
5+
string += str(i)
6+
res.append(string)
7+
return '\n'.join(res)
8+
9+
10+
11+
for i in (13,):
12+
print(pattern(i))

[leetcode]Isomorphic Strings.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
class Solution:
2+
# @param {string} s
3+
# @param {string} t
4+
# @return {boolean}
5+
def isIsomorphic(self, s, t):
6+
def isomorphic(s,t):
7+
d = {}
8+
for k,v in zip(s,t):
9+
d[k] = v
10+
return ''.join([d[c] for c in s]) == t
11+
return isomorphic(s,t) and isomorphic(t,s)
12+
13+
test = Solution()
14+
print(test.isIsomorphic('ab','aa'))
15+
print(test.isIsomorphic('egg','add'))
16+
print(test.isIsomorphic('egg','adv'))
17+
print(test.isIsomorphic('paper','title'))
18+
print(test.isIsomorphic('paper','title'))

[leetcode]Length of Last Word.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
class Solution:
2+
# @param {string} s
3+
# @return {integer}
4+
def lengthOfLastWord(self, s):
5+
num = 0
6+
s = s.strip()
7+
for c in s[::-1]:
8+
if c == ' ':
9+
break
10+
num += 1
11+
return num
12+
13+
test = Solution()
14+
print(test.lengthOfLastWord('H '))

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy