10 2017 档案
摘要:Given an array where elements are sorted in ascending order, convert it to a height balanced BST. 思路:既然数组里的元素已经按升序排好序了,那么不难想到用二分法来做这道题。 /** * Definiti
阅读全文
摘要:Given a non-empty 2D array grid of 0's and 1's, an island is a group of 1's (representing land) connected 4-directionally (horizontal or vertical.) Yo
阅读全文
摘要:Given an unsorted array of integers, find the length of longest continuous increasing subsequence. Example 1: Example 2: Note: Length of the array wil
阅读全文
摘要:Given a binary array, find the maximum number of consecutive 1s in this array. Example 1: Note: The input array will only contain 0 and 1. The length
阅读全文
摘要:Given a non-negative integer represented as a non-empty array of digits, plus one to the integer. You may assume the integer do not contain any leadin
阅读全文
摘要:Given an integer array, find three numbers whose product is maximum and output the maximum product. Example 1: Input: [1,2,3] Output: 6 Example 2: Inp
阅读全文
摘要:Given a non-empty array of integers, return the third maximum number in this array. If it does not exist, return the maximum number. The time complexi
阅读全文
摘要:Given an array nums, write a function to move all 0's to the end of it while maintaining the relative order of the non-zero elements. For example, giv
阅读全文
摘要:Given a sorted array and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in or
阅读全文
摘要:Given an array of 2n integers, your task is to group these integers into n pairs of integer, say (a1, b1), (a2, b2), ..., (an, bn) which makes sum of
阅读全文
摘要:Given an array and a value, remove all instances of that value in place and return the new length. Do not allocate extra space for another array, you
阅读全文
摘要:Given two sorted integer arrays nums1 and nums2, merge nums2 into nums1 as one sorted array. Note:You may assume that nums1 has enough space (size tha
阅读全文
摘要:Given a sorted array, remove the duplicates in place such that each element appear only once and return the new length. Do not allocate extra space fo
阅读全文
摘要:Given an array containing n distinct numbers taken from 0, 1, 2, ..., n, find the one that is missing from the array. For example,Given nums = [0, 1,
阅读全文
摘要:Given an array of integers and an integer k, you need to find the number of unique k-diff pairs in the array. Here a k-diff pair is defined as an inte
阅读全文
摘要:Given a binary tree, determine if it is height-balanced. For this problem, a height-balanced binary tree is defined as a binary tree in which the dept
阅读全文
摘要:Given a binary tree, find its minimum depth. The minimum depth is the number of nodes along the shortest path from the root node down to the nearest l
阅读全文
摘要:Given a binary tree, find its maximum depth. The maximum depth is the number of nodes along the longest path from the root node down to the farthest l
阅读全文
摘要:Invert a binary tree. to 1 /** 2 * Definition for a binary tree node. 3 * public class TreeNode { 4 * int val; 5 * TreeNode left; 6 * TreeNode right;
阅读全文
摘要:Given a binary search tree and the lowest and highest boundaries as L and R, trim the tree so that all its elements lies in [L, R] (R >= L). You might
阅读全文
摘要:Given a Binary Search Tree (BST), convert it to a Greater Tree such that every key of the original BST is changed to the original key plus sum of all
阅读全文
摘要:Given two binary trees, write a function to check if they are equal or not. Two binary trees are considered equal if they are structurally identical a
阅读全文
摘要:Given a binary tree and a sum, determine if the tree has a root-to-leaf path such that adding up all the values along the path equals the given sum. F
阅读全文
摘要:Write a function to delete a node (except the tail) in a singly linked list, given only access to that node. Supposed the linked list is 1 -> 2 -> 3 -
阅读全文