Quellcode durchsuchen

New problem done

master
Lachlan Jacob vor 5 Jahren
Ursprung
Commit
d56b66114f
3 geänderte Dateien mit 29 neuen und 0 gelöschten Zeilen
  1. 16
    0
      problems/58/main.py
  2. 10
    0
      problems/58/problem.txt
  3. 3
    0
      problems/58/run.sh

+ 16
- 0
problems/58/main.py Datei anzeigen

@@ -0,0 +1,16 @@
class Solution:
def lengthOfLastWord(self, s: str) -> int:
s = s.strip()
for i in range(len(s) - 1, -1, -1):
if s[i] == " ":
print("Found space at", i, len(s) - 1)
if i == len(s) - 1:
return 0
else:
return len(s[i+1:])
return len(s)

s = Solution()
print("Expected: 0")
print("Got:", s.lengthOfLastWord("Test"))

+ 10
- 0
problems/58/problem.txt Datei anzeigen

@@ -0,0 +1,10 @@
Given a string s consists of upper/lower-case alphabets and empty space characters ' ', return the length of last word (last word means the last appearing word if we loop from left to right) in the string.

If the last word does not exist, return 0.

Note: A word is defined as a maximal substring consisting of non-space characters only.

Example:

Input: "Hello World"
Output: 5

+ 3
- 0
problems/58/run.sh Datei anzeigen

@@ -0,0 +1,3 @@
#!/bin/bash

python3 main.py

Laden…
Abbrechen
Speichern