Skip to content

Commit a75c36e

Browse files
authored
Add files via upload
1 parent b189189 commit a75c36e

File tree

3 files changed

+49
-12
lines changed

3 files changed

+49
-12
lines changed

problem-1/README.md

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,20 @@
11
# Problem 1
22

3-
Link:
3+
Link: https://leetcode.com/problems/length-of-last-word/description/
44

5-
## Benchmarks
5+
##Benchmarks
6+
7+
Benchmark 1: python3 problem-1.py
8+
Time (mean ± σ): 11.1 ms ± 1.6 ms [User: 9.4 ms, System: 1.8 ms]
9+
Range (min … max): 8.8 ms … 22.1 ms 212 runs
10+
11+
Warning: Statistical outliers were detected. Consider re-running this benchmark on a quiet system without any interferences from other programs. It might help to use the '--warmup' or '--prepare' options.
12+
13+
Benchmark 2: mojo problem-1.mojo
14+
Time (mean ± σ): 222.3 ms ± 9.7 ms [User: 238.4 ms, System: 28.6 ms]
15+
Range (min … max): 205.5 ms … 238.0 ms 14 runs
16+
17+
##Which performed better?
18+
'python3 problem-1.py' ran
19+
19.95 ± 3.02 times faster than 'mojo problem-1.mojo'
620

7-
CPU | Mem | Time

problem-1/problem-1.mojo

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,23 @@
11
from python import Python
2+
3+
from python import Python
4+
25
def lengthOfLastWord(enterword: String):
3-
let py = Python.import_module("builtins")
6+
py = Python.import_module("builtins")
7+
48
count = 0
59
for i in range(len(enterword)-1, -1, -1):
610
if enterword[i] != " ":
711
count += 1
812
elif count > 0:
913
break
10-
return count
11-
12-
# Taking input from the user
13-
def main():
14-
let py = Python.import_module("builtins")
15-
enterword = py.input("Enter a string: ")
16-
let result = lengthOfLastWord(enterword)
1714

1815
print("Length of the last word:")
19-
print(result)
16+
print(count)
17+
18+
# Main function
19+
def main():
20+
input_string = "Hello World"
21+
lengthOfLastWord(input_string)
22+
23+

problem-1/problem-1.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
def lengthOfLastWord(enterword):
2+
"""
3+
:type s: str
4+
:rtype: int
5+
"""
6+
7+
count = 0
8+
9+
for i in range(len(enterword)-1, -1, -1):
10+
if enterword[i] != " ":
11+
count += 1
12+
elif count > 0:
13+
break
14+
15+
return count
16+
17+
def main():
18+
input_string = "Hello World"
19+
result = lengthOfLastWord(input_string)
20+
#print("Length of the last word:s

0 commit comments

Comments
 (0)