Easy 充分利用BST的properties. /** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeN…
分类:LeetCode
2018-09-27 215. Kth Largest Element in an Array
题意:给你一个无序数组,返回该数组第K大的数(重复的两个数算两个)。 解题思路:使用优先队列priority_queue<int> q; 一、优先队列声明方式: priority_queue<int, …
23. 合并K个排序链表
解法很多 将所有的 ListNode放到数组中,然后排序, 再输出 变为2路合并 题眼 这个题目就是考察的堆. python 中的heapq import heapq class Solution(object): de…
[LeetCode] Stickers to Spell Word 贴片拼单词
We are given N different types of stickers. Each sticker has a lowercase English word on it. You would …
LeetCode | Reorder List
题目: Given a singly linked list L: L0→L1→…→Ln-1→Ln, reorder it to: L0→Ln→L1→Ln-1→L2→Ln-2→… You m…
[array] leetcode - 48. Rotate Image - Medium
leetcode – 48. Rotate Image – Medium descrition You are given an n x n 2D matrix representing an i…
超级大正整数的减法实现
要求实现明显超过整型以及其他计量的整数范围的减法。如有a,b的大型整数,规定了a>=b,求两个数相减的结果。代码如下,通过处理字符串,用字符的相减来实现,需要考虑几个边界条件。 其中,输入为a-b的格式,如:111…
300. Longest Increasing Subsequence
/* * 300. Longest Increasing Subsequence QuestionEditorial Solution My Submissions Total Accepted: 34958 Total…
[LeetCode] Path Sum 二叉树的路径和
Given a binary tree and a sum, determine if the tree has a root-to-leaf path such that adding up all th…
[LeetCode] Subarray Product Less Than K 子数组乘积小于K
Your are given an array of positive integers nums. Count and print the number of (contiguous) subarrays…
[LeetCode] Prime Number of Set Bits in Binary Representation 二进制表示中的非零位个数为质数
Given two integers L and R, find the count of numbers in the range [L, R] (inc…
[LintCode][System Design] Consistent Hashing
Problem 一般的数据库进行horizontal shard的方法是指,把 id 对 数据库服务器总数 n 取模,然后来得到他在哪台机器上。这种方法的缺点是,当数据继续增加,我们需要增加数据库服务器,将 n 变为 n…