Algorithm: find the last character and return the distance between it and the first one.
We can use helper pointer:
Alternatively, we can use just index:
main.cpp:
Output:
String: ""
Length: 0
String: "a"
Length: 1
String: "ab"
Length: 2
String: "abc"
Length: 3
String: "abcdefg"
Length: 7
Length: 0
String: "a"
Length: 1
String: "ab"
Length: 2
String: "abc"
Length: 3
String: "abcdefg"
Length: 7
No comments:
Post a Comment