12 2018 档案
摘要:Given preorder and inorder traversal of a tree, construct the binary tree. Note:You may assume that duplicates do not exist in the tree. For example,
阅读全文
posted @ 2018-12-31 19:23
fatttcat
摘要:Serialization is the process of converting a data structure or object into a sequence of bits so that it can be stored in a file or memory buffer, or
阅读全文
posted @ 2018-12-31 15:44
fatttcat
摘要:Given a binary tree, flatten it to a linked list in-place. For example, given the following tree: The flattened tree should look like: 每个节点的右节点都是preor
阅读全文
posted @ 2018-12-31 15:01
fatttcat
摘要:Given a binary tree, imagine yourself standing on the right side of it, return the values of the nodes you can see ordered from top to bottom. Example
阅读全文
posted @ 2018-12-31 12:06
fatttcat
摘要: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 n
阅读全文
posted @ 2018-12-31 11:39
fatttcat
摘要:Given a binary tree, determine if it is a valid binary search tree (BST). Assume a BST is defined as follows: The left subtree of a node contains only
阅读全文
posted @ 2018-12-31 09:37
fatttcat
摘要:A binary tree is univalued if every node in the tree has the same value. Return true if and only if the given tree is univalued. Example 1: Example 2:
阅读全文
posted @ 2018-12-31 08:08
fatttcat
摘要:Given an n-ary tree, return the preorder traversal of its nodes' values. For example, given a 3-ary tree: Return its preorder traversal as: [1,3,5,6,2
阅读全文
posted @ 2018-12-31 08:01
fatttcat
摘要:Given an n-ary tree, return the postorder traversal of its nodes' values. For example, given a 3-ary tree: Return its postorder traversal as: [5,6,3,2
阅读全文
posted @ 2018-12-31 07:51
fatttcat
摘要:Given a non-empty binary tree, return the average value of the nodes on each level in the form of an array. Example 1: Note: M1: BFS 注意!sum要用long,用int
阅读全文
posted @ 2018-12-31 07:31
fatttcat
摘要: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
阅读全文
posted @ 2018-12-31 06:51
fatttcat
摘要:Given a binary search tree (BST) with duplicates, find all the mode(s) (the most frequently occurred element) in the given BST. Assume a BST is define
阅读全文
posted @ 2018-12-30 17:51
fatttcat
摘要:Given a binary tree, return the tilt of the whole tree. The tilt of a tree node is defined as the absolute difference between the sum of all left subt
阅读全文
posted @ 2018-12-30 11:36
fatttcat
摘要:If the depth of a tree is smaller than 5, then this tree can be represented by a list of three-digits integers. For each integer in this list: Given a
阅读全文
posted @ 2018-12-30 11:23
fatttcat
摘要:You are given a binary tree in which each node contains an integer value. Find the number of paths that sum to a given value. The path does not need t
阅读全文
posted @ 2018-12-30 10:58
fatttcat
摘要:Given a binary tree and a sum, find all root-to-leaf paths where each path's sum equals the given sum. Note: A leaf is a node with no children. Exampl
阅读全文
posted @ 2018-12-30 10:41
fatttcat
摘要: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. N
阅读全文
posted @ 2018-12-30 10:07
fatttcat
摘要:You need to construct a string consists of parenthesis and integers from a binary tree with the preorder traversing way. The null node needs to be rep
阅读全文
posted @ 2018-12-30 10:00
fatttcat
摘要:Given a tree, rearrange the tree in in-order so that the leftmost node in the tree is now the root of the tree, and every node has no left child and o
阅读全文
posted @ 2018-12-30 09:43
fatttcat
摘要:Given a non-empty special binary tree consisting of nodes with the non-negative value, where each node in this tree has exactly two or zero sub-node.
阅读全文
posted @ 2018-12-30 09:14
fatttcat
摘要:Given a binary tree, find the length of the longest path where each node in the path has the same value. This path may or may not pass through the roo
阅读全文
posted @ 2018-12-30 08:28
fatttcat
摘要:Consider all the leaves of a binary tree. From left to right order, the values of those leaves form a leaf value sequence. For example, in the given t
阅读全文
posted @ 2018-12-30 07:32
fatttcat
摘要: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
阅读全文
posted @ 2018-12-29 18:11
fatttcat
摘要: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
阅读全文
posted @ 2018-12-29 17:14
fatttcat
摘要:Given a Binary Search Tree and a target number, return true if there exist two elements in the BST such that their sum is equal to the given target. E
阅读全文
posted @ 2018-12-29 16:47
fatttcat
摘要:Given a n-ary 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 le
阅读全文
posted @ 2018-12-29 15:28
fatttcat
摘要:Find the sum of all left leaves in a given binary tree. Example: M1: recursive time: O(n), space: O(height) M2: iterative 对于每一个节点,检查它的left child是不是lea
阅读全文
posted @ 2018-12-29 15:09
fatttcat
摘要:Given an n-ary tree, return the level order traversal of its nodes' values. (ie, from left to right, level by level). For example, given a 3-ary tree:
阅读全文
posted @ 2018-12-29 05:42
fatttcat
摘要:Given a binary tree, return the zigzag level order traversal of its nodes' values. (ie, from left to right, then right to left for the next level and
阅读全文
posted @ 2018-12-29 05:25
fatttcat
摘要:Given a binary tree, return the bottom-up level order traversal of its nodes' values. (ie, from left to right, level by level from leaf to root). For
阅读全文
posted @ 2018-12-29 05:04
fatttcat
摘要:Given a binary tree, return the level order traversal of its nodes' values. (ie, from left to right, level by level). For example:Given binary tree [3
阅读全文
posted @ 2018-12-29 04:49
fatttcat
摘要:Given the root node of a binary search tree (BST) and a value. You need to find the node in the BST that the node's value equals the given value. Retu
阅读全文
posted @ 2018-12-28 17:22
fatttcat
摘要:Given two binary trees, write a function to check if they are the same or not. Two binary trees are considered the same if they are structurally ident
阅读全文
posted @ 2018-12-28 17:17
fatttcat
摘要:Given a binary tree, you need to compute the length of the diameter of the tree. The diameter of a binary tree is the length of the longest path betwe
阅读全文
posted @ 2018-12-28 15:52
fatttcat
摘要:Given a binary tree, return all root-to-leaf paths. Note: A leaf is a node with no children. Example: backtracking, 记得返回上层的时候删掉该层节点 time: O(n) -- visi
阅读全文
posted @ 2018-12-28 15:06
fatttcat
摘要:Given two non-empty binary trees s and t, check whether tree t has exactly the same structure and node values with a subtree of s. A subtree of s is a
阅读全文
posted @ 2018-12-28 13:23
fatttcat
摘要:Invert a binary tree. Example: Input: Output: Trivia:This problem was inspired by this original tweet by Max Howell: time: O(n), space: O(logn)
阅读全文
posted @ 2018-12-28 11:05
fatttcat
摘要: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
阅读全文
posted @ 2018-12-28 10:58
fatttcat
摘要: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 dep
阅读全文
posted @ 2018-12-28 10:54
fatttcat
摘要:Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center). For example, this binary tree [1,2,2,3,4,4,3] is symmet
阅读全文
posted @ 2018-12-28 09:38
fatttcat
摘要:Given two binary trees and imagine that when you put one of them to cover the other, some nodes of the two trees are overlapped while the others are n
阅读全文
posted @ 2018-12-28 09:07
fatttcat
摘要: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
阅读全文
posted @ 2018-12-27 19:00
fatttcat
摘要:Given a node from a cyclic linked list which is sorted in ascending order, write a function to insert a value into the list such that it remains a cyc
阅读全文
posted @ 2018-12-27 18:43
fatttcat
摘要:Given a (singly) linked list with head node root, write a function to split the linked list into k consecutive linked list "parts". The length of each
阅读全文
posted @ 2018-12-27 16:35
fatttcat
摘要:Given a non-negative integer represented as non-empty a singly linked list of digits, plus one to the integer. You may assume the integer do not conta
阅读全文
posted @ 2018-12-27 16:14
fatttcat
摘要:Sort a linked list using insertion sort. A graphical example of insertion sort. The partial sorted list (black) initially contains only the first elem
阅读全文
posted @ 2018-12-27 15:57
fatttcat
摘要:We are given head, the head node of a linked list containing unique integer values. We are also given the list G, a subset of the values in the linked
阅读全文
posted @ 2018-12-27 15:15
fatttcat
摘要:Given a linked list, rotate the list to the right by k places, where k is non-negative. Example 1: Example 2: time: O(n), space: O(1)
阅读全文
posted @ 2018-12-27 14:49
fatttcat
摘要:Given a sorted linked list, delete all nodes that have duplicate numbers, leaving only distinct numbers from the original list. Example 1: Example 2:
阅读全文
posted @ 2018-12-27 14:12
fatttcat
摘要: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
阅读全文
posted @ 2018-12-27 13:39
fatttcat
摘要:Design a Phone Directory which supports the following operations: Example: M1: 用linked hast set,通过iterator得到具体元素 docs: https://docs.oracle.com/javase/
阅读全文
posted @ 2018-12-27 13:00
fatttcat
摘要:Write a function to delete a node (except the tail) in a singly linked list, given only access to that node. Given linked list -- head = [4,5,1,9], wh
阅读全文
posted @ 2018-12-27 12:29
fatttcat
摘要:You are given a doubly linked list which in addition to the next and previous pointers, it could have a child pointer, which may or may not point to a
阅读全文
posted @ 2018-12-27 09:20
fatttcat
摘要:Design your implementation of the linked list. You can choose to use the singly linked list or the doubly linked list. A node in a singly linked list
阅读全文
posted @ 2018-12-27 07:58
fatttcat
摘要:Given a sorted linked list, delete all duplicates such that each element appear only once. Example 1: Example 2: time: O(n), space: O(1)
阅读全文
posted @ 2018-12-27 07:08
fatttcat
摘要:Write a program to find the node at which the intersection of two singly linked lists begins. For example, the following two linked lists: begin to in
阅读全文
posted @ 2018-12-27 06:47
fatttcat
摘要:Convert a BST to a sorted circular doubly-linked list in-place. Think of the left and right pointers as synonymous to the previous and next pointers i
阅读全文
posted @ 2018-12-27 04:56
fatttcat
摘要:Given a linked list, return the node where the cycle begins. If there is no cycle, return null. To represent a cycle in the given linked list, we use
阅读全文
posted @ 2018-12-26 19:28
fatttcat
摘要:Given a linked list, reverse the nodes of a linked list k at a time and return its modified list. k is a positive integer and is less than or equal to
阅读全文
posted @ 2018-12-26 17:37
fatttcat
摘要:A linked list is given such that each node contains an additional random pointer which could point to any node in the list or null. Return a deep copy
阅读全文
posted @ 2018-12-26 16:23
fatttcat
摘要:Given a string, determine if a permutation of the string could form a palindrome. Example 1: Example 2: Example 3: 扫一遍s,统计频率,奇数频率最多只能出现一次。用cnt表示结果,cnt
阅读全文
posted @ 2018-12-26 16:04
fatttcat
摘要:Given a singly linked list, determine if it is a palindrome. Example 1: Example 2: Follow up:Could you do it in O(n) time and O(1) space? 找中点,反转后半部分,再
阅读全文
posted @ 2018-12-26 11:15
fatttcat
摘要:Remove all elements from a linked list of integers that have value val. Example: time: O(n), space: O(1)
阅读全文
posted @ 2018-12-26 11:06
fatttcat
摘要:Given a linked list and a value x, partition it such that all nodes less than x come before nodes greater than or equal to x. You should preserve the
阅读全文
posted @ 2018-12-26 10:22
fatttcat
摘要:Given a singly linked list L: L0→L1→…→Ln-1→Ln,reorder it to: L0→Ln→L1→Ln-1→L2→Ln-2→… You may not modify the values in the list's nodes, only nodes its
阅读全文
posted @ 2018-12-26 10:08
fatttcat
摘要:Given a non-empty, singly linked list with head node head, return a middle node of linked list. If there are two middle nodes, return the second middl
阅读全文
posted @ 2018-12-24 15:02
fatttcat
摘要:A strobogrammatic number is a number that looks the same when rotated 180 degrees (looked at upside down). Write a function to determine if a number i
阅读全文
posted @ 2018-12-24 09:34
fatttcat
摘要:Write an algorithm to determine if a number is "happy". A happy number is a number defined by the following process: Starting with any positive intege
阅读全文
posted @ 2018-12-24 09:23
fatttcat
摘要:Design a logger system that receive stream of messages along with its timestamps, each message should be printed if and only if it is not printed in t
阅读全文
posted @ 2018-12-24 09:06
fatttcat
摘要:Given a list of strings words representing an English Dictionary, find the longest word in words that can be built one character at a time by other wo
阅读全文
posted @ 2018-12-24 08:51
fatttcat
摘要:Given two lists Aand B, and B is an anagram of A. B is an anagram of A means B is made by randomizing the order of the elements in A. We want to find
阅读全文
posted @ 2018-12-24 07:41
fatttcat
摘要:Given two sentences words1, words2 (each represented as an array of strings), and a list of similar word pairs pairs, determine if two sentences are s
阅读全文
posted @ 2018-12-22 18:17
fatttcat
摘要:Given an array of balls, where the color of the balls can only be Red, Green or Blue, sort the balls such that all the Red balls are grouped on the le
阅读全文
posted @ 2018-12-22 15:35
fatttcat
摘要:Given a non-empty list of words, return the k most frequent elements. Your answer should be sorted by frequency from highest to lowest. If two words h
阅读全文
posted @ 2018-12-22 07:35
fatttcat
摘要:Given a non-empty array of integers, return the k most frequent elements. Example 1: Input: nums = [1,1,1,2,2,3], k = 2 Output: [1,2] Example 2: Input
阅读全文
posted @ 2018-12-20 10:01
fatttcat
摘要:Roman numerals are represented by seven different symbols: I, V, X, L, C, D and M. For example, two is written as II in Roman numeral, just two one's
阅读全文
posted @ 2018-12-20 07:43
fatttcat
摘要:Roman numerals are represented by seven different symbols: I, V, X, L, C, D and M. For example, two is written as II in Roman numeral, just two one's
阅读全文
posted @ 2018-12-20 06:23
fatttcat
摘要:Given a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST. For this problem, a height-balanced bina
阅读全文
posted @ 2018-12-19 19:14
fatttcat
摘要:Given an array where elements are sorted in ascending order, convert it to a height balanced BST. For this problem, a height-balanced binary tree is d
阅读全文
posted @ 2018-12-19 18:43
fatttcat
摘要:Sort a linked list in O(n log n) time using constant space complexity. Example 1: Example 2: divide and conquer + merge sort,先找中点,断开,再merge time: O(nl
阅读全文
posted @ 2018-12-19 18:17
fatttcat
摘要:Given a binary tree, find the lowest common ancestor (LCA) of two given nodes in the tree. According to the definition of LCA on Wikipedia: “The lowes
阅读全文
posted @ 2018-12-19 17:53
fatttcat
摘要: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 Wikipedia
阅读全文
posted @ 2018-12-19 16:28
fatttcat
摘要:Calculate the sum of two integers a and b, but you are not allowed to use the operator + and -. Example 1: Input: a = 1, b = 2 Output: 3 Example 2: In
阅读全文
posted @ 2018-12-19 15:35
fatttcat
摘要:sort & comparator 各种排序方法总结 bit manipulation A summary: how to use bit manipulation to solve problems
阅读全文
posted @ 2018-12-19 14:57
fatttcat
摘要:In an alien language, surprisingly they also use english lowercase letters, but possibly in a different order. The order of the alphabet is some permu
阅读全文
posted @ 2018-12-19 14:52
fatttcat
摘要:Given a nested list of integers, return the sum of all integers in the list weighted by their depth. Each element is either an integer, or a list -- w
阅读全文
posted @ 2018-12-19 14:25
fatttcat
摘要:Given a nested list of integers, return the sum of all integers in the list weighted by their depth. Each element is either an integer, or a list -- w
阅读全文
posted @ 2018-12-19 13:51
fatttcat
摘要:You are given a data structure of employee information, which includes the employee's unique id, his importance value and his directsubordinates' id.
阅读全文
posted @ 2018-12-19 13:19
fatttcat
摘要:Suppose an array sorted in ascending order is rotated at some pivot unknown to you beforehand. (i.e., [0,1,2,4,5,6,7] might become [4,5,6,7,0,1,2]). F
阅读全文
posted @ 2018-12-19 12:40
fatttcat
摘要:Implement atoi which converts a string to an integer. The function first discards as many whitespace characters as necessary until the first non-white
阅读全文
posted @ 2018-12-19 12:09
fatttcat
摘要:Given an array w of positive integers, where w[i] describes the weight of index i, write a function pickIndex which randomly picks an index in proport
阅读全文
posted @ 2018-12-19 10:07
fatttcat
摘要:Given two non-negative integers num1 and num2 represented as string, return the sum of num1 and num2. Note: The length of both num1 and num2 is < 5100
阅读全文
posted @ 2018-12-19 05:12
fatttcat
摘要:The API: int read4(char *buf) reads 4 characters at a time from a file. The return value is the actual number of characters read. For example, it retu
阅读全文
posted @ 2018-12-19 04:43
fatttcat
摘要:The API: int read4(char *buf) reads 4 characters at a time from a file. The return value is the actual number of characters read. For example, it retu
阅读全文
posted @ 2018-12-19 04:09
fatttcat
摘要:Given a linked list, remove the n-th node from the end of list and return its head. Example: Given linked list: 1->2->3->4->5, and n = 2. After removi
阅读全文
posted @ 2018-12-18 10:25
fatttcat
摘要:Given two integers dividend and divisor, divide two integers without using multiplication, division and mod operator. Return the quotient after dividi
阅读全文
posted @ 2018-12-18 09:30
fatttcat
摘要:Given a non-empty string s, you may delete at most one character. Judge whether you can make it a palindrome. Example 1: Input: "aba" Output: True Exa
阅读全文
posted @ 2018-12-18 07:54
fatttcat
摘要:Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases. Note: For the purpose of this problem, w
阅读全文
posted @ 2018-12-18 07:23
fatttcat
摘要:A sentence S is given, composed of words separated by spaces. Each word consists of lowercase and uppercase letters only. We would like to convert the
阅读全文
posted @ 2018-12-18 07:08
fatttcat
摘要:Given a 32-bit signed integer, reverse digits of an integer. Example 1: Example 2: Example 3: Note:Assume we are dealing with an environment which cou
阅读全文
posted @ 2018-12-18 06:38
fatttcat
摘要:You are given an n x n 2D matrix representing an image. Rotate the image by 90 degrees (clockwise). Note: You have to rotate the image in-place, which
阅读全文
posted @ 2018-12-18 04:47
fatttcat
摘要:Determine whether an integer is a palindrome. An integer is a palindrome when it reads the same backward as forward. Example 1: Example 2: Example 3:
阅读全文
posted @ 2018-12-17 19:07
fatttcat
摘要:Implement strStr(). Return the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack. Example 1: Input: haystac
阅读全文
posted @ 2018-12-17 18:43
fatttcat
摘要:Given a non-empty binary search tree and a target value, find the value in the BST that is closest to the target. Note: Given target value is a floati
阅读全文
posted @ 2018-12-17 18:27
fatttcat
摘要:Given an integer array sorted in ascending order, write a function to search target in nums. If target exists, then return its index, otherwise return
阅读全文
posted @ 2018-12-17 14:04
fatttcat
摘要:There are two sorted arrays nums1 and nums2 of size m and n respectively. Find the median of the two sorted arrays. The overall run time complexity sh
阅读全文
posted @ 2018-12-17 13:22
fatttcat
摘要:There are a row of n houses, each house can be painted with one of the three colors: red, blue or green. The cost of painting each house with a certai
阅读全文
posted @ 2018-12-17 10:53
fatttcat
摘要:Get the Kth number in the Fibonacci Sequence. (K is 0-indexed, the 0th Fibonacci number is 0 and the 1st Fibonacci number is 1). Examples 0th fibonacc
阅读全文
posted @ 2018-12-17 09:34
fatttcat
摘要:Given a list of sorted characters letters containing only lowercase letters, and given a target letter target, find the smallest element in the list t
阅读全文
posted @ 2018-12-17 08:38
fatttcat
摘要:Given a target integer T, a non-negative integer K and an integer array A sorted in ascending order, find the K closest numbers to T in A. Assumptions
阅读全文
posted @ 2018-12-16 14:52
fatttcat
摘要:Write a program that outputs the string representation of numbers from 1 to n. But for multiples of three it should output “Fizz” instead of the numbe
阅读全文
posted @ 2018-12-16 08:50
fatttcat
摘要:Given a paragraph and a list of banned words, return the most frequent word that is not in the list of banned words. It is guaranteed there is at leas
阅读全文
posted @ 2018-12-16 08:34
fatttcat
摘要:Given a target integer T and an integer array A sorted in ascending order, find the index of the last occurrence of T in A or return -1 if there is no
阅读全文
posted @ 2018-12-16 06:07
fatttcat
摘要:Given a target integer T and an integer array A sorted in ascending order, find the index of the first occurrence of T in A or return -1 if there is n
阅读全文
posted @ 2018-12-16 06:03
fatttcat
摘要:Given a target integer T and an integer array A sorted in ascending order, find the index i in A such that A[i] is closest to T. Assumptions There can
阅读全文
posted @ 2018-12-15 18:19
fatttcat
摘要:Given a sorted (in ascending order) integer array nums of n elements and a target value, write a function to search target in nums. If targetexists, t
阅读全文
posted @ 2018-12-15 17:44
fatttcat
摘要:Write a function that reverses a string. The input string is given as an array of characters char[]. Do not allocate extra space for another array, yo
阅读全文
posted @ 2018-12-15 15:43
fatttcat
摘要:Given a linked list, swap every two adjacent nodes and return its head. Example: Note: Your algorithm should use only constant extra space. You may no
阅读全文
posted @ 2018-12-15 10:18
fatttcat
摘要:You are given two non-empty linked lists representing two non-negative integers. The most significant digit comes first and each of their nodes contai
阅读全文
posted @ 2018-12-15 08:04
fatttcat
摘要:You are given two non-empty linked lists representing two non-negative integers. The digits are stored in reverse order and each of their nodes contai
阅读全文
posted @ 2018-12-15 06:47
fatttcat
摘要:Reverse a linked list from position m to n. Do it in one-pass. Note: 1 ≤ m ≤ n ≤ length of list. Example: 只反转从m到n的部分链表 M1: iterative 首先找到prev的位置(开始反转位
阅读全文
posted @ 2018-12-15 03:54
fatttcat
摘要:Given two binary strings, return their sum (also a binary string). The input strings are both non-empty and contains only characters 1 or 0. Example 1
阅读全文
posted @ 2018-12-14 09:34
fatttcat
摘要:Reverse a singly linked list. Example: Follow up: A linked list can be reversed either iteratively or recursively. Could you implement both? M1: itera
阅读全文
posted @ 2018-12-10 20:47
fatttcat
摘要:Given an array of numbers nums, in which exactly two elements appear only once and all the other elements appear exactly twice. Find the two elements
阅读全文
posted @ 2018-12-09 13:49
fatttcat
摘要:Suppose you are at a party with n people (labeled from 0 to n - 1) and among them, there may exist one celebrity. The definition of a celebrity is tha
阅读全文
posted @ 2018-12-09 11:21
fatttcat
摘要:Some people will make friend requests. The list of their ages is given and ages[i] is the age of the ith person. Person A will NOT friend request pers
阅读全文
posted @ 2018-12-09 10:36
fatttcat
摘要:Given a m x n matrix, if an element is 0, set its entire row and column to 0. Do it in-place. Example 1: Example 2: Follow up: A straight forward solu
阅读全文
posted @ 2018-12-09 09:23
fatttcat
摘要:Given an array, rotate the array to the right by k steps, where k is non-negative. Example 1: Input: [1,2,3,4,5,6,7] and k = 3 Output: [5,6,7,1,2,3,4]
阅读全文
posted @ 2018-12-09 07:13
fatttcat
摘要:Given an array nums of n integers where n > 1, return an array output such that output[i] is equal to the product of all the elements of nums except n
阅读全文
posted @ 2018-12-08 18:56
fatttcat
摘要:Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses. For example, given n = 3, a solution set is: M
阅读全文
posted @ 2018-12-07 12:12
fatttcat
摘要:Given a robot cleaner in a room modeled as a grid. Each cell in the grid can be empty or blocked. The robot cleaner with 4 given APIs can move forward
阅读全文
posted @ 2018-12-07 08:47
fatttcat
摘要:Given an integer array, your task is to find all the different possible increasing subsequences of the given array, and the length of an increasing su
阅读全文
posted @ 2018-12-06 19:00
fatttcat
摘要:Find all possible combinations of k numbers that add up to a number n, given that only numbers from 1 to 9 can be used and each combination should be
阅读全文
posted @ 2018-12-06 18:40
fatttcat
摘要:Given a collection of candidate numbers (candidates) and a target number (target), find all unique combinations in candidates where the candidate numb
阅读全文
posted @ 2018-12-06 17:42
fatttcat
摘要:Given a set of candidate numbers (candidates) (without duplicates) and a target number (target), find all unique combinations in candidates where the
阅读全文
posted @ 2018-12-06 17:24
fatttcat
摘要:Given a collection of numbers that might contain duplicates, return all possible unique permutations. Example: backtracking 和permutations不同的是可以有重复元素。先
阅读全文
posted @ 2018-12-06 17:05
fatttcat
摘要:Given a collection of distinct integers, return all possible permutations. Example: backtracking 为了防止值重复,用visited数组标记该元素在每一层递归的时候是否被访问过,注意递归到最底层pop元素回
阅读全文
posted @ 2018-12-06 16:56
fatttcat
摘要:Given a collection of integers that might contain duplicates, nums, return all possible subsets (the power set). Note: The solution set must not conta
阅读全文
posted @ 2018-12-06 14:16
fatttcat
摘要:Given a set of distinct integers, nums, return all possible subsets (the power set). Note: The solution set must not contain duplicate subsets. Exampl
阅读全文
posted @ 2018-12-06 14:00
fatttcat
摘要:Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the following properties: Integers in each row are sorted i
阅读全文
posted @ 2018-12-05 07:48
fatttcat
摘要:Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the following properties: Integers in each row are sorted f
阅读全文
posted @ 2018-12-05 07:32
fatttcat
摘要:Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity. Example: divide and conquer,用merge 2 sorted list作为函
阅读全文
posted @ 2018-12-04 18:16
fatttcat
摘要:Given a set of N people (numbered 1, 2, ..., N), we would like to split everyone into two groups of any size. Each person may dislike some other peopl
阅读全文
posted @ 2018-12-04 15:22
fatttcat
摘要:Given an undirected graph, return true if and only if it is bipartite. Recall that a graph is bipartite if we can split it's set of nodes into two ind
阅读全文
posted @ 2018-12-04 14:40
fatttcat
摘要:Given an array of integers nums sorted in ascending order, find the starting and ending position of a given target value. Your algorithm's runtime com
阅读全文
posted @ 2018-12-04 13:53
fatttcat
摘要:Implement pow(x, n), which calculates x raised to the power n (xn). Example 1: Example 2: Example 3: Note: -100.0 < x < 100.0 n is a 32-bit signed int
阅读全文
posted @ 2018-12-04 13:28
fatttcat
摘要:Suppose an array sorted in ascending order is rotated at some pivot unknown to you beforehand. (i.e., [0,0,1,2,2,5,6] might become [2,5,6,0,0,1,2]). Y
阅读全文
posted @ 2018-12-04 12:27
fatttcat
摘要:Suppose an array sorted in ascending order is rotated at some pivot unknown to you beforehand. (i.e., [0,1,2,4,5,6,7] might become [4,5,6,7,0,1,2]). Y
阅读全文
posted @ 2018-12-04 11:47
fatttcat
摘要:Given a sorted array, two integers k and x, find the k closest elements to x in the array. The result should also be sorted in ascending order. If the
阅读全文
posted @ 2018-12-04 09:25
fatttcat
摘要:You are a product manager and currently leading a team to develop a new product. Unfortunately, the latest version of your product fails the quality c
阅读全文
posted @ 2018-12-04 05:13
fatttcat
摘要:Suppose an array sorted in ascending order is rotated at some pivot unknown to you beforehand. (i.e., [0,1,2,4,5,6,7] might become [4,5,6,7,0,1,2]). F
阅读全文
posted @ 2018-12-04 04:59
fatttcat
摘要: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 endp
阅读全文
posted @ 2018-12-04 02:57
fatttcat
摘要:Given two strings s and t, determine if they are isomorphic. Two strings are isomorphic if the characters in s can be replaced to get t. All occurrenc
阅读全文
posted @ 2018-12-03 18:04
fatttcat
摘要:Given an array with n objects colored red, white or blue, sort them in-place so that objects of the same color are adjacent, with the colors in the or
阅读全文
posted @ 2018-12-03 17:25
fatttcat
摘要:Comparing Methods a.compareTo(b); //按字典顺序比较两个字符串,返回0: a=b, 返回正数: a > b, 返回负数: a < b Sorting Methods Arrays.sort(); //字母序优先于长度Collections.sort(); Custo
阅读全文
posted @ 2018-12-03 15:04
fatttcat
摘要: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
阅读全文
posted @ 2018-12-03 14:55
fatttcat
摘要:Say you have an array for which the ith element is the price of a given stock on day i. Design an algorithm to find the maximum profit. You may comple
阅读全文
posted @ 2018-12-03 14:12
fatttcat
摘要:Given a sorted array nums, remove the duplicates in-place such that each element appear only once and return the new length. Do not allocate extra spa
阅读全文
posted @ 2018-12-03 13:45
fatttcat
摘要:Given two arrays, write a function to compute their intersection. Example 1: Example 2: Input: nums1 = [4,9,5], nums2 = [9,4,9,8,4] Output: [4,9] Exam
阅读全文
posted @ 2018-12-03 13:27
fatttcat
摘要:Given an array of integers, return indices of the two numbers such that they add up to a specific target. You may assume that each input would have ex
阅读全文
posted @ 2018-12-03 12:27
fatttcat
摘要:Given two sorted integer arrays nums1 and nums2, merge nums2 into nums1 as one sorted array. Note: The number of elements initialized in nums1 and num
阅读全文
posted @ 2018-12-02 18:52
fatttcat
摘要:Given a non-negative index k where k ≤ 33, return the kth index row of the Pascal's triangle. Note that the row index starts from 0. In Pascal's trian
阅读全文
posted @ 2018-12-02 18:32
fatttcat
摘要:Given a non-negative integer numRows, generate the first numRows of Pascal's triangle. In Pascal's triangle, each number is the sum of the two numbers
阅读全文
posted @ 2018-12-02 17:30
fatttcat
摘要:Given a non-empty array of digits representing a non-negative integer, plus one to the integer. The digits are stored such that the most significant d
阅读全文
posted @ 2018-12-02 15:46
fatttcat
摘要: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. Example: Note: 用
阅读全文
posted @ 2018-12-02 15:16
fatttcat
摘要:An array is monotonic if it is either monotone increasing or monotone decreasing. An array A is monotone increasing if for all i <= j, A[i] <= A[j]. A
阅读全文
posted @ 2018-12-02 15:02
fatttcat
摘要:用binary search 如果A[mid] < A[mid+1],说明peak在mid右侧,l = mid + 1;否则说明peak在mid右侧,r = mid 时间:O(N),空间:O(1)
阅读全文
posted @ 2018-12-02 12:10
fatttcat
摘要:Given an array of integers that is already sorted in ascending order, find two numbers such that they add up to a specific target number. The function
阅读全文
posted @ 2018-12-02 10:02
fatttcat
摘要:Given an array of integers and an integer k, you need to find the total number of continuous subarrays whose sum equals to k. Example 1: Note: 解法:hash
阅读全文
posted @ 2018-12-02 09:56
fatttcat
摘要:Given two sparse matrices A and B, return the result of AB. You may assume that A's column number is equal to B's row number. Example: Input: A = [ [
阅读全文
posted @ 2018-12-02 04:53
fatttcat
摘要:Design and implement a TwoSum class. It should support the following operations: add and find. add - Add the number to an internal data structure.find
阅读全文
posted @ 2018-12-01 17:04
fatttcat
摘要:Given two strings A and B, find the minimum number of times A has to be repeated such that B is a substring of it. If no such solution, return -1. For
阅读全文
posted @ 2018-12-01 14:54
fatttcat
摘要:You are given a map in form of a two-dimensional integer grid where 1 represents land and 0 represents water. Grid cells are connected horizontally/ve
阅读全文
posted @ 2018-12-01 14:52
fatttcat
摘要:Design and implement a data structure for Least Recently Used (LRU) cache. It should support the following operations: get and put. get(key) - Get the
阅读全文
posted @ 2018-12-01 07:31
fatttcat
浙公网安备 33010602011771号