Skip to content

Commit c01039e

Browse files
committed
Remove prints and format files
1 parent a8e8668 commit c01039e

File tree

10 files changed

+34
-49
lines changed

10 files changed

+34
-49
lines changed

problem-1/problem-1.mojo

100644100755
Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
1-
fn lengthOfLastWord(enterword: String):
1+
fn lengthOfLastWord(enterword: String) -> Int:
22
var count: Int = 0
3-
for i in range(len(enterword)-1, -1, -1):
3+
4+
for i in range(len(enterword) - 1, -1, -1):
45
if enterword[i] != " ":
56
count += 1
67
elif count > 0:
78
break
89

9-
print("Length of the last word:", count)
10+
return count
1011

1112

1213
fn main():
1314
for _ in range(100000):
14-
lengthOfLastWord("Hello World")
15+
_ = lengthOfLastWord("Hello World")

problem-1/problem-1.py

100644100755
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
def length_of_last_word(enterword):
2-
32
count = 0
43

54
for i in range(len(enterword)-1, -1, -1):
@@ -8,7 +7,8 @@ def length_of_last_word(enterword):
87
elif count > 0:
98
break
109

11-
print("Length of last word", count)
10+
return count
11+
1212

1313
def main():
1414
[length_of_last_word("Hello World") for _ in range(100000)]

problem-2/problem-2.mojo

100644100755
Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,19 @@
11
fn checkRecord(attendance_record: String) -> Bool:
22
var attendance_record_str = attendance_record
3-
43
var absent_count = 0
54
var late_count = 0
65

76
for i in range(len(attendance_record_str)):
8-
9-
if attendance_record_str[i] == 'A':
7+
if attendance_record_str[i] == "A":
108
absent_count += 1
119
late_count = 0
12-
elif attendance_record_str[i] == 'L':
10+
elif attendance_record_str[i] == "L":
1311
late_count += 1
1412
else:
1513
late_count = 0
16-
1714
if late_count >= 3 or absent_count >= 2:
18-
print("The attendance record is not acceptable.")
1915
return False
2016

21-
print("The attendance record is acceptable.")
2217
return True
2318

2419

problem-2/problem-2.py

100644100755
Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,24 @@
11
def check_record(attendance_record):
2-
32
attendance_record_str = str(attendance_record)
4-
53
absent_count = 0
64
late_count = 0
75

86
for i in range(len(attendance_record_str)):
9-
107
if attendance_record_str[i] == 'A':
118
absent_count += 1
129
late_count = 0
1310
elif attendance_record_str[i] == 'L':
1411
late_count += 1
1512
else:
1613
late_count = 0
17-
1814
if late_count >= 3 or absent_count >= 2:
19-
print("The attendance record is not acceptable.")
15+
# print("The attendance record is not acceptable.")
2016
return False
2117

22-
print("The attendance record is acceptable.")
18+
# print("The attendance record is acceptable.")
2319
return True
2420

2521

26-
# Main function
2722
def main():
2823
[check_record("PPALLP") for _ in range(100000)]
2924

problem-3/problem-3.mojo

100644100755
Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,17 @@
1-
import math
2-
3-
fn makeGood(s: String):
1+
fn makeGood(s: String) -> String:
42
var result = str("")
5-
63
var i = 0
7-
while i < len(s):
8-
9-
if i < len(s) - 1 and math.abs(ord(s[i]) - ord(s[i + 1])) == 32:
104

5+
while i < len(s):
6+
if i < len(s) - 1 and abs(ord(s[i]) - ord(s[i + 1])) == 32:
117
i += 2
128
else:
13-
149
result = result + s[i]
1510
i += 1
1611

17-
print(result)
12+
return result
13+
1814

1915
fn main():
2016
for _ in range(1000000):
21-
makeGood("leEeetcode")
17+
_ = makeGood("leEeetcode")

problem-3/problem-3.py

100644100755
Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
11
def make_good(s):
22
result = ""
3-
43
i = 0
5-
while i < len(s):
64

5+
while i < len(s):
76
if i < len(s) - 1 and abs(ord(s[i]) - ord(s[i + 1])) == 32:
8-
97
i += 2
108
else:
11-
129
result += s[i]
1310
i += 1
1411

problem-4/problem-4.mojo

100644100755
Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
fn detectCapitalUse(word: String) -> Bool:
22
var uinput = word
3-
43
var number_of_capital_letters = 0
4+
55
for i in range(len(uinput)):
66
var letter = uinput[i]
77
if ord(letter) < 97:
88
number_of_capital_letters += 1
99

1010
var number_of_small_letters = len(uinput) - number_of_capital_letters
1111

12-
if number_of_capital_letters == len(uinput) or number_of_small_letters == len(uinput) or (ord(word[0]) < 97 and number_of_capital_letters == 1):
12+
if number_of_capital_letters == len(uinput)
13+
or number_of_small_letters == len(uinput)
14+
or (ord(word[0]) < 97 and number_of_capital_letters == 1):
1315
return True
1416
else:
1517
return False

problem-4/problem-4.py

100644100755
Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
1-
21
def detect_capital_use(word):
3-
4-
52
uinput = str(word)
6-
73
number_of_capital_letters = 0
4+
85
for i in range(len(uinput)):
96
letter = uinput[i]
107
if ord(letter) < 97:
118
number_of_capital_letters += 1
129

1310
number_of_small_letters = len(uinput) - number_of_capital_letters
1411

15-
if number_of_capital_letters == len(uinput) or number_of_small_letters == len(uinput) or (ord(word[0]) < 97 and number_of_capital_letters == 1):
12+
if (number_of_capital_letters == len(uinput)
13+
or number_of_small_letters == len(uinput)
14+
or (ord(word[0]) < 97 and number_of_capital_letters == 1)):
1615
return True
1716
else:
1817
return False

problem-5/problem-5.mojo

100644100755
Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1-
fn findTheDifference(s:String, t:String):
1+
fn findTheDifference(s:String, t:String) -> String:
2+
var result = str("")
3+
24
for i in range(len(t)):
35
if s[i] != t[i]:
4-
var result = t[i]
5-
print("The difference is:")
6-
print(result)
7-
break
6+
result = t[i]
7+
8+
return result
89

910

1011
fn main():
1112
for _ in range(100000):
12-
findTheDifference("abcd", "abced")
13+
_ = findTheDifference("abcd", "abced")

problem-5/problem-5.py

100644100755
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
def find_the_difference(s, t):
2-
32
for i in range(len(t)):
43
if s[i] != t[i]:
54
result = t[i]
65
break
76

8-
print("The difference is:", result)
7+
return result
98

109

1110
def main():

0 commit comments

Comments
 (0)