题目描述:
The demons had captured the princess (P) and imprisoned her in the bottom-right corner of a dungeon. The dungeon consists of M x N rooms laid out in a 2D grid. Our valiant knight (K) was initially positioned in ...
The demons had captured the princess (P) and imprisoned her in the bottom-right corner of a dungeon. The dungeon consists of M x N rooms laid out in a 2D grid. Our valiant knight (K) was initially positioned in ...
Sort a linked list using insertion sort.
使用插入排序对链表排序。
朴素版本( 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 ...
Implement an iterator over a binary search tree (BST). Your iterator will be initialized with the root node of a BST.
Calling next() will return the next smallest number in the BST.
Note: next() and hasNext() should run in ...
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 ...
Related to question Excel Sheet Column Title
Given a column title as appear in an Excel sheet, return its corresponding column number.
For example:
A -> 1
B -> 2
C -> 3
...
Z -> 26
AA -> 27 ...