
算法
HuangHongkai_
这个作者很懒,什么都没留下…
展开
-
LeetCode44. Wildcard Matching (DP,注意初始化)
Given an input string (s) and a pattern (p), implement wildcard pattern matching with support for '?' and '*'.'?' Matches any single character.'*' Matches any sequence of characters (including the e...原创 2018-10-31 13:23:30 · 214 阅读 · 0 评论 -
LeetCode 126. Word Ladder II (构造最短路径模型)
Given two words (beginWord and endWord), and a dictionary’s word list, find all shortest transformation sequence(s) from beginWord to endWord, such that:Only one letter can be changed at a timeEach...原创 2018-11-02 17:07:13 · 277 阅读 · 0 评论 -
LeetCode 95. Unique Binary Search Trees II (二叉搜索树计数,卡特兰数)
Given an integer n, generate all structurally unique BST’s (binary search trees) that store values 1 … n.Example:Input: 3Output:[ [1,null,3,2], [3,2,null,1], [3,1,null,null,2], [2,1,3], ...原创 2018-11-02 12:23:46 · 203 阅读 · 0 评论 -
LeetCode 715. Range Module / 57. Insert Interval(区间查询更新,离散化)
A Range Module is a module that tracks ranges of numbers. Your task is to design and implement the following interfaces in an efficient manner.addRange(int left, int right) Adds the half-open interva...原创 2018-11-03 23:31:05 · 445 阅读 · 0 评论 -
LeetCode 687. Longest Univalue Path (dfs+bfs)
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 root.Note: The length of path between two nodes is r...原创 2018-11-01 22:22:01 · 144 阅读 · 0 评论 -
LeetCode719. Find K-th Smallest Pair Distance (二分法,滑动窗口优化)
Given an integer array, return the k-th smallest distance among all the pairs. The distance of a pair (A, B) is defined as the absolute difference between A and B.Example 1:Input:nums = [1,3,1]k =...原创 2018-11-03 16:31:49 · 229 阅读 · 0 评论 -
LeetCode222. Count Complete Tree Nodes (完全二叉树节点计数技巧)
Given a complete binary tree, count the number of nodes.Note:Definition of a complete binary tree from Wikipedia:In a complete binary tree every level, except possibly the last, is completely fille...原创 2018-11-01 19:00:41 · 248 阅读 · 0 评论 -
LeetCode41. First Missing Positive (数组技巧)
Given an unsorted integer array, find the smallest missing positive integer.Example 1:Input: [1,2,0]Output: 3Example 2:Input: [3,4,-1,1]Output: 2Example 3:Input: [7,8,9,11,12]Output: 1Not...原创 2018-11-03 11:11:09 · 161 阅读 · 0 评论 -
LeetCode 891. Sum of Subsequence Widths (找规律)
Given an array of integers A, consider all non-empty subsequences of A.For any sequence S, let the width of S be the difference between the maximum and minimum element of S.Return the sum of the wid...原创 2018-11-03 09:26:32 · 212 阅读 · 0 评论 -
LeetCode874. Walking Robot Simulation (模拟题)
A robot on an infinite grid starts at point (0, 0) and faces north. The robot can receive one of three possible types of commands:-2: turn left 90 degrees-1: turn right 90 degrees1 <= x <= ...原创 2018-10-30 19:06:11 · 171 阅读 · 0 评论 -
LeetCode 5. Longest Palindromic Substring (DP)
Given a string s, find the longest palindromic substring in s. You may assume that the maximum length of s is 1000.Example 1:Input: "babad"Output: "bab"Note: "aba" is also a valid answer.Example...原创 2018-10-30 13:34:38 · 130 阅读 · 0 评论 -
Leetcode312. Burst Balloons (DP+DFS)
Given n balloons, indexed from 0 to n-1. Each balloon is painted with a number on it represented by array nums. You are asked to burst all the balloons. If the you burst balloon i you will get nums[le...原创 2018-10-30 13:06:08 · 154 阅读 · 0 评论 -
LeetCode 685. Redundant Connection II (判断环,有向树,并查集)
In this problem, a rooted tree is a directed graph such that, there is exactly one node (the root) for which all other nodes are descendants of this node, plus every node has exactly one parent, excep...原创 2018-10-31 16:50:47 · 330 阅读 · 0 评论 -
LeetCode 4. Median of Two Sorted Arrays (求两个有序数组第k大数字,分治法)
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 should be O(log (m+n)).You may assume nums1 and num...原创 2018-11-02 23:42:06 · 481 阅读 · 0 评论