File tree Expand file tree Collapse file tree 10 files changed +34
-49
lines changed Expand file tree Collapse file tree 10 files changed +34
-49
lines changed Original file line number Diff line number Diff line change 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
1213fn main ():
1314 for _ in range (100000 ):
14- lengthOfLastWord(" Hello World" )
15+ _ = lengthOfLastWord(" Hello World" )
Original file line number Diff line number Diff line change 11def 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
1313def main ():
1414 [length_of_last_word ("Hello World" ) for _ in range (100000 )]
Original file line number Diff line number Diff line change 11fn 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
Original file line number Diff line number Diff line change 11def 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
2722def main ():
2823 [check_record ("PPALLP" ) for _ in range (100000 )]
2924
Original file line number Diff line number Diff line change 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
1915fn main ():
2016 for _ in range (1000000 ):
21- makeGood(" leEeetcode" )
17+ _ = makeGood(" leEeetcode" )
Original file line number Diff line number Diff line change 11def 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
Original file line number Diff line number Diff line change 11fn 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
Original file line number Diff line number Diff line change 1-
21def 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
Original file line number Diff line number Diff line change 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
1011fn main ():
1112 for _ in range (100000 ):
12- findTheDifference(" abcd" , " abced" )
13+ _ = findTheDifference(" abcd" , " abced" )
Original file line number Diff line number Diff line change 11def 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
1110def main ():
You can’t perform that action at this time.
0 commit comments