-
-
Notifications
You must be signed in to change notification settings - Fork 298
/
Copy path806.py
35 lines (30 loc) · 1.14 KB
/
806.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
__________________________________________________________________________________________________
sample 24 ms submission
class Solution:
def numberOfLines(self, widths: List[int], S: str) -> List[int]:
letters = 'abcdefghijklmnopqrstuvwxyz'
keys = list(letters)
print(keys)
letter_width = dict(zip(keys, widths))
ptr = 0
lines = 1
for i in range(len(S)):
if ptr + letter_width[S[i]] > 100:
lines += 1
ptr = letter_width[S[i]]
else:
ptr += letter_width[S[i]]
return [lines, ptr]
__________________________________________________________________________________________________
sample 13000 kb submission
class Solution:
def numberOfLines(self, widths, S):
lines, width = 1, 0
for c in S:
w = widths[ord(c) - ord('a')]
width += w
if width > 100:
lines += 1
width = w
return lines, width
__________________________________________________________________________________________________