摘要:
定义一个函数,输入一个链表的头节点,反转该链表并输出反转后链表的头节点。 输入: 1->2->3->4->5->NULL 输出: 5->4->3->2->1->NULL 双指针:定义两个指针,pre指向空,cur指向头节点,然后不断遍历cur,将 cur 的 next 指向 pre,然后 pre 和 阅读全文
posted @ 2020-08-28 09:47
ninian
阅读(65)
评论(0)
推荐(0)
摘要:
输入一个链表的头节点,从尾到头反过来返回每个节点的值(用数组返回)。 反转:从头到尾将链表打印到数组中,返回反转后的结果即可。 class Solution: def reversePrint(self, head): res = [] while head: res.append(head.val 阅读全文
posted @ 2020-08-28 09:00
ninian
阅读(97)
评论(0)
推荐(0)
摘要:
请实现一个函数,把字符串 s 中的每个空格替换成"%20"。 输入:s = "We are happy." 输出:"We%20are%20happy class solution(object): def replacespace(self,s): """ :type s: str :rtype: 阅读全文
posted @ 2020-08-28 08:43
ninian
阅读(61)
评论(0)
推荐(0)

浙公网安备 33010602011771号