Complete the solution so that it returns true if the first argument(string) passed in ends with the 2nd argument (also a string).
Examples:
solution('abc', 'bc') // returns true
solution('abc', 'd') // returns false
要点
- 用迭代器初始化字符串的方式截取出字符串的尾部
- 要在str长度>ending 时立即返回false
#include <string>
bool solution(std::string const &str, std::string const &ending) {
if(str.length() < ending.length() ) return false ;
std::string tail(str.end()-ending.length() , str.end() );
return tail == ending ;
}