随笔分类 - algorithm
摘要:Implement next permutation, which rearranges numbers into the lexicographically next greater permutation of numbers. If such arrangement is not po ssi
阅读全文
摘要:1 public class BinarySearchSolution 2 { 3 public int BinarySearch(int[] array, int target) 4 { 5 int low = 0, high = array.Length; ...
阅读全文
摘要:Given a string, find the length of the longest substring T that contains at most k distinct characters. For example, Given s = “eceba” and k = 2, T is
阅读全文
摘要:Note:A subtree must include all of its descendants.Here's an example: The Largest BST Subtree in this case is the highlighted one. The return value is
阅读全文
摘要:Given an array nums and a target value k, find the maximum length of a subarray that sums to k. If there isn't one, return 0 instead. Note:The sum of
阅读全文
摘要:Write a function to generate the generalized abbreviations of a word. Example: Given word = "word", return the following list (order does not matter):
阅读全文
摘要:Given a binary tree, return the vertical order traversal of its nodes' values. (ie, from top to bottom, column by column). If two nodes are in the sam
阅读全文
摘要:Given a binary tree, find the length of the longest consecutive sequence path. The path refers to any sequence of nodes from some starting node to any
阅读全文
摘要:Given a pattern and a string str, find if str follows the same pattern. Here follow means a full match, such that there is a bijection between a lette
阅读全文
摘要:Given a binary search tree and a node in it, find the in-order successor of that node in the BST. Note: If the given node has no in-order successor in
阅读全文
摘要:Given an unsorted array nums, reorder it in-place such that nums[0] <= nums[1] >= nums[2] <= nums[3].... For example, given nums = [3, 5, 2, 1, 6, 4],
阅读全文
摘要: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
阅读全文
摘要:Design an algorithm to encode a list of strings to a string. The encoded string is then sent over the network and is decoded back to the original list
阅读全文
摘要:Given a non-empty binary search tree and a target value, find k values in the BST that are closest to the target. Note: Given target value is a floati
阅读全文
摘要: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
阅读全文
摘要:Given a string s, return all the palindromic permutations (without duplicates) of it. Return an empty list if no palindromic permutation could be form
阅读全文
摘要:There are a row of n houses, each house can be painted with one of the k colors. The cost of painting each house with a certain color is different. Yo
阅读全文
摘要:Given n nodes labeled from 0 to n - 1 and a list of undirected edges (each edge is a pair of nodes), write a function to check whether these edges mak
阅读全文
摘要:Given an array of n integers nums and a target, find the number of index triplets i, j, k with 0 <= i < j < k < n that satisfy the condition nums[i] +
阅读全文
摘要: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
阅读全文

浙公网安备 33010602011771号