标签归档:leetcode

RSS feed of leetcode

[LeetCode]Compare Version Numbers

题目描述:

Compare two version numbers version1 and version2.
If version1 > version2 return 1, if version1 < version2 return -1, otherwise return 0.

You may assume that the version strings are non-empty and contain only digits and the . character.
The ...

继续阅读

[Leetcode]Sort List

题目描述:

Sort a linked list in O(n log n) time using constant space complexity.

题目大意:

使用常数空间复杂度,对一个链表执行O(n log n)时间复杂度的排序

解题思路:

归并排序,链表的中点可以通过“快慢指针”法求得。

Python代码:

# Definition for singly-linked list.
# class ListNode:
#     def __init__(self, x):
#         self.val = x
#         self ...

继续阅读