给定一个排序链表,删除所有含有重复数字的节点,只保留原始链表中 没有重复出现 的数字. 思路和上一题类似(参考 力扣(LeetCode)删除排序链表中的重复元素 个人题解)) 只不过这里需要用到一个前置节点来排除第一个节点就是重复元素的特例. 同样是使用快慢针解决问题.不再详细叙述. 代码如下: class Solution { public ListNode deleteDuplicates(ListNode head) { ListNode ret = new ListNode(0); re
本题是力扣网第50题. 实现 pow(x, n) ,即计算 x 的 n 次幂函数. 采用递归和非递归思路python实现. class Solution: #递归思路 def myPow_recursion(self,x,n): if n == 0: #递归终止条件,n==0返回1 return 1 if n < 0: #n小于0,就返回其倒数,-n和其递归结构一致 return 1 / self.myPow_recursion(x,-n) if n & 1: #判断是奇数,则结果为x*(x
题目描述: python实现 Search in Rotated Sorted Array2 搜索旋转排序数组 中文: 假设按照升序排序的数组在预先未知的某个点上进行了旋转. ( 例如,数组 [0,0,1,2,2,5,6] 可能变为 [2,5,6,0,0,1,2] ). 编写一个函数来判断给定的目标值是否存在于数组中.若存在返回 true,否则返回 false. 英文: Suppose an array sorted in ascending order is rotated at some
题目描述: 中文: 给定一个链表,返回链表开始入环的第一个节点. 如果链表无环,则返回 null. 为了表示给定链表中的环,我们使用整数 pos 来表示链表尾连接到链表中的位置(索引从 0 开始). 如果 pos 是 -1,则在该链表中没有环. 说明:不允许修改给定的链表. 英文: Given a linked list, return the node where the cycle begins. If there is no cycle, return null. To represent
题目描述: 中文: 给定一个链表,判断链表中是否有环. 为了表示给定链表中的环,我们使用整数 pos 来表示链表尾连接到链表中的位置(索引从 0 开始). 如果 pos 是 -1,则在该链表中没有环. 英文: Given a linked list, determine if it has a cycle in it. To represent a cycle in the given linked list, we use an integer pos which represents the
题目描述: 中文: 给定一个链表,两两交换其中相邻的节点,并返回交换后的链表. 你不能只是单纯的改变节点内部的值,而是需要实际的进行节点交换. 示例: 给定 1->2->3->4, 你应该返回 2->1->4->3. 英文: Given a linked list, swap every two adjacent nodes and return its head. You may not modify the values in the list's nodes, o
题目描述: 中文: 给定一个链表,删除链表的倒数第 n 个节点,并且返回链表的头结点. 示例: 给定一个链表: 1->2->3->4->5, 和 n = 2. 当删除了倒数第二个节点后,链表变为 1->2->3->5. 说明: 给定的 n 保证是有效的. 进阶: 你能尝试使用一趟扫描实现吗? 英文: Given a linked list, remove the n-th node from the end of list and return its head.
题目描述: 中文: 给定一个排序链表,删除所有重复的元素,使得每个元素只出现一次. 示例 1: 输入: 1->1->2输出: 1->2 示例 2: 输入: 1->1->2->3->3输出: 1->2->3 英文: Given a sorted linked list, delete all duplicates such that each element appear only once. Example 1: Input: 1->1->
题目描述: 中文: 给定一个链表和一个特定值 x,对链表进行分隔,使得所有小于 x 的节点都在大于或等于 x 的节点之前. 你应当保留两个分区中每个节点的初始相对位置. 示例: 输入: head = 1->4->3->2->5->2, x = 3输出: 1->2->2->4->3->5 英文: Given a linked list and a value x, partition it such that all nodes less than
题目描述: 中文: 给定一个非空整数数组,除了某个元素只出现一次以外,其余每个元素均出现两次.找出那个只出现了一次的元素. 说明: 你的算法应该具有线性时间复杂度. 你可以不使用额外空间来实现吗? 英文: Given a non-empty array of integers, every element appears twice except for one. Find that single one. Note: Your algorithm should have a linear ru