leetcode面试准备: Maximal Rectangle 1 题目 Given a 2D binary matrix filled with 0's and 1's, find the largest rectangle containing all ones and return its area. 接口: int maximalRectangle(char[][] matrix) 2 思路 这是一道非常综合的题目,要求在0-1矩阵中找出面积最大的全1矩阵.刚看到这道题会比较无从下手,b
leetcode面试准备: Game of Life 1 题目 According to the Wikipedia's article: "The Game of Life, also known simply as Life, is a cellular automaton devised by the British mathematician John Horton Conway in 1970." Given a board with m by n cells, each c
leetcode面试准备: Word Pattern 1 题目 Given a pattern and a string str, find if str follows the same pattern. Examples: pattern = "abba", str = "dog cat cat dog" should return true. pattern = "abba", str = "dog cat cat fish&qu
leetcode面试准备:Add and Search Word - Data structure design 1 题目 Design a data structure that supports the following two operations: void addWord(word) bool search(word) search(word) can search a literal word or a regular expression string containing on
leetcode面试准备:Reverse Words in a String 1 题目 Given an input string, reverse the string word by word. For example, Given s = "the sky is blue", return "blue is sky the". Update (2015-02-12): For C programmers: Try to solve it in-place in
leetcode面试准备:Implement Trie (Prefix Tree) 1 题目 Implement a trie withinsert, search, and startsWith methods. Note: You may assume that all inputs are consist of lowercase letters a-z. 2 思路 该题是实现trie树. Trie,又称单词查找树或键树,是一种树形结构.典型应用是用于统计和排序大量的字符串(但不仅限于字符
leetcode面试准备:Triangle 1 题目 Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjacent numbers on the row below. For example, given the following triangle [ [2], [3,4], [6,5,7], [4,1,8,3] ] The minimum path sum
leetcode面试准备:Sliding Window Maximum 1 题目 Given an array nums, there is a sliding window of size k which is moving from the very left of the array to the very right. You can only see the k numbers in the window. Each time the sliding window moves righ
leetcode面试准备:Simplify Path 1 题目 Given an absolute path for a file (Unix-style), simplify it. For example, path = "/home/", => "/home" path = "/a/./b/../../c/", => "/c" Corner Cases: Did you consider the case w
leetcode面试准备:Kth Largest Element in an Array 1 题目 Find the kth largest element in an unsorted array. Note that it is the kth largest element in the sorted order, not the kth distinct element. For example, Given [3,2,1,5,6,4] and k = 2, return 5. Note
leetcode面试准备:Minimum Size Subarray Sum 1 题目 Given an array of n positive integers and a positive integer s, find the minimal length of a subarray of which the sum ≥ s. If there isn't one, return 0 instead. For example, given the array [2,3,1,2,4,3] a
leetcode面试准备: Substring with Concatenation of All Words 1 题目 You are given a string, s, and a list of words, words, that are all of the same length. Find all starting indices of substring(s) in s that is a concatenation of each word in words exactly
leetcode面试准备:Valid Anagram 1 题目 Given two strings s and t, write a function to determine if t is an anagram of s. For example, s = "anagram", t = "nagaram", return true. s = "rat", t = "car", return false. Note: You
leetcode面试准备:Divide Two Integers 1 题目 Divide two integers without using multiplication, division and mod operator. If it is overflow, return MAX_INT. 接口: public int divide(int dividend, int divisor) 2 思路 题意 不用乘.除.mod 做一个除法运算. 解 直接用除数去一个一个加,直到被除数被超过的话
leetcode面试准备:Container With Most Water 1 题目 Given n non-negative integers a1, a2, ..., an, where each represents a point at coordinate (i, ai). n vertical lines are drawn such that the two endpoints of line i is at (i, ai) and (i, 0). Find two lines,
leetcode面试准备:Lowest Common Ancestor of a Binary Search Tree & Binary Tree 1 题目 Binary Search Tree的LCA Given a binary search tree (BST), find the lowest common ancestor (LCA) of two given nodes in the BST. According to the definition of LCA on Wikiped
1 题目 You are given two linked lists representing two non-negative numbers. The digits are stored in reverse order and each of their nodes contain a single digit. Add the two numbers and return it as a linked list. Input: (2 -> 4 -> 3) + (5 -> 6 -
1 题目 Description: Count the number of prime numbers less than a non-negative number, n. 接口:public int countPrimes(int n); 2 思路 统计小于n的素数个数,注意不包括n. 思路1:素数的判断 很容易想到素数的判断isPrime,然后逐个数来进行判断是否是素数.进行统计,输出结果. 复杂度: 把isPrime时间复杂度控制在O(n^0.5)的话,因此:Time:O(n^1.5)
1 题目 Contains Duplicate I Given an array of integers, find if the array contains any duplicates. Your function should return true if any value appears at least twice in the array, and it should return false if every element is distinct. 接口: public bo