[LeetCode]Insertion Sort List

题目描述:

Sort a linked list using insertion sort.

题目大意:

使用插入排序对链表排序。

Python代码:

朴素版本( Accepted 2568ms ):

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

class Solution:
    # @param head, a ListNode
    # @return a ListNode
    def ...

继续阅读

[LeetCode]Factorial Trailing Zeroes

题目描述:

Given an integer n, return the number of trailing zeroes in n!.

Note: Your solution should be in polynomial time complexity.

题目大意:

给定一个整数n,返回n!(n的阶乘)数字中的后缀0的个数。

注意:你的解法应该满足多项式时间复杂度。

解题思路:

参考博文:http://www.geeksforgeeks.org/count-trailing-zeroes-factorial-number/

朴素解法:

首先求出n!,然后计算末尾0的个数。(重复÷10 ...

继续阅读

年度归档