类别归档:LeetCode

LeetCode OJ is a platform for preparing technical coding interviews.

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]Intersection of Two Linked Lists

题目描述:

Write a program to find the node at which the intersection of two singly linked lists begins.

For example, the following two linked lists:

A:          a1 → a2
                   ↘
                     c1 → c2 → c3
                   ↗            
B:     b1 → b2 → b3

begin to intersect at node ...

继续阅读

[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 ...

继续阅读