leetcode Longest Increasing Path in a Matrix
Given an integer matrix, find the length of the longest increasing path.
From each cell, you can either move to four directions: left, right, up or down. You may NOT move diagonally or move outside of the boundary (i.e. wrap-around is not allowed).
nums = [
The longest increasing path is
[1, 2, 6, 9].
leetcode Odd Even Linked List
Given a singly linked list, group all odd nodes together followed by the even nodes. Please note here we are talking about the node number and not the value in the nodes.
You should try to do it in place. The program should run in O(1) space complexity and O(nodes) time complexity.
The relative order inside both the even and odd groups should remain as it was in the input.
The first node is considered odd, the second node even and so on …
Lowest Common Ancestor of a Binary Tree 问题描述
Given a binary tree, find the lowest common ancestor of two given nodes in the tree.
leetcode Count of Range Sum
Given an integer array
nums, return the number of range sums that lie in
S(i, j)is defined as the sum of the elements in
A naive algorithm of O(n2) is trivial. You MUST do better than that.
Given nums =
[-2, 5, -1], lower =
-2, upper =
The three ranges are :
[0, 2]and their respective sums are:
-2, -1, 2.
leetcode Power of Three
Given an integer, write a function to determine if it is a power of three.
Could you do it without using any loop / recursion?
leetcode 274 H-Index
Given an array of citations (each citation is a non-negative integer) of a researcher, write a function to compute the researcher’s h-index.
According to the definition of h-index on Wikipedia: “A scientist has index h if h of his/her N papers have at least h citations each, and the other N − h papers have no more than h citations each.”
For example, given
citations = [3, 0, 6, 1, 5], which means the researcher has
5papers in total and each of them had received
3, 0, 6, 1, 5citations respectively. Since the researcher has
3papers with at least
3citations each and the remaining two with no more than
3citations each, his h-index is
Note: If there are several possible values for
h, the maximum one is taken as the h-index.
- An easy approach is to sort the array first.
- What are the possible values of h-index?
- A faster approach is to use extra space.
火影忍者 剧场版 博人传 影评