20251203【携程】面试算法真题(共1题)

题目1:反转句子

全部评论
def reverse_words(sentence): words = [] current_word = [] for char in sentence: if char == ' ': if current_word: words.append(''.join(current_word)) current_word = [] else: current_word.append(char) if current_word: words.append(''.join(current_word)) reversed_sentence = '' for i in range(len(words) - 1, -1, -1): reversed_sentence += words[i] if i != 0: reversed_sentence += ' ' return reversed_sentence
点赞 回复 分享
发布于 12-04 09:03 广东

相关推荐

11-26 09:30
复旦大学 Java
点赞 评论 收藏
分享
评论
点赞
1
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务