class ListNode(object): def __init__(self, x): self.val = x self.next = None def reverseList(self, head): if head == None or head.next == None: return head p = head.next while p.next: p1 = p.next p.next = head head, p = p, p1 p.next = head return p
def func(listNode): listNode.reverse() for i in listNode: print(i) li = [1,2,3,4,5] func(li) 利用python列表函数reverse()将列表倒叙,然后遍历打印,但是这有一个缺点就是改变了原列表的顺序.看看下面的代码: def func(listNode): array = listNode[::-1] for i in array: print(i) li = [1,2,3,4,5] func(li)
google测试工程师的一道题: 设计一个函数,使用任意语言,完成以下功能: 一个句子,将句子中的单词全部倒排过来,但单词的字母顺序不变.比如,This is a real world,输出结果为 world real a is this. 下面利用python来实现: 句子为: #!/usr/bin/env python3.4 # -*- coding: utf-8 -*- #某一段文字 data = "You don’t need us to tell you that China’s In
题目描述: 写一个函数,实现输入一个字符串,然后把其中的元音字母倒叙 注意 元音字母包含大小写,元音字母有五个a,e,i,o,u 原文描述: Write a function that takes a string as input and reverse only the vowels of a string. Example 1: Given s = "hello", return "holle". Example 2: Given s = "leet
根据Problem Solving with Algorithms and Data Structures using Python 一书用python实现链表 书籍在线网址http://interactivepython.org/runestone/static/pythonds/index.html 中文翻译书籍:https://facert.gitbooks.io/python-data-structure-cn/ class Node: #链表中单个节点的实现 def __init__(