JinFei's Blog

Thinking will not overcome fear but action will.

[LeetCode]128. Longest Consecutive Sequence

最长连续的序列

题目描述 Given an unsorted array of integers, find the length of the longest consecutive elements sequence. Your algorithm should run in O(n) complexity. Example1: Input: [100, 4, 200, 1, ...

[LeetCode]301. Remove Invalid Parentheses

返回有效的括号

题目描述 Remove the minimum number of invalid parentheses in order to make the input string valid. Return all possible results. Note: The input string may contain letters other than the parenthese...

[LeetCode]1143. Longest Common Subsequence

dp,最长公共子串

题目描述 Given two strings text1 and text2, return the length of their longest common subsequence. A subsequence of a string is a new string generated from the original string with some characte...

[LeetCode]逛街

递减栈

题目描述 小Q在周末的时候和他的小伙伴来到大城市逛街,一条步行街上有很多高楼,共有n座高楼排成一行。 小Q从第一栋一直走到了最后一栋,小Q从来都没有见到这么多的楼,所以他想知道他在每栋楼的位置处能看到多少栋楼呢?(当前面的楼的高度大于等于后面的楼时,后面的楼将被挡住) Example1: 输入第一行将包含一个数字n,代表楼的栋数,接下来的一行将包含n...

[LeetCode]42. Trapping Rain Water

盛最多的水

题目描述 Given n non-negative integers representing an elevation map where the width of each bar is 1, compute how much water it is able to trap after raining. Example1: Input: [0,1,0,2,1,0,1...

[LeetCode]72. Edit Distance

dp,编辑距离

题目描述 Given two words word1 and word2, find the minimum number of operations required to convert word1 to word2. You have the following 3 operations permitted on a word: Insert a ...

[剑指Offer]最小的K个数

STL,multiset使用greater重载函数,优先级队列堆

题目描述 输入n个整数,找出其中最小的K个数。例如输入4,5,1,6,2,7,3,8这8个数字,则最小的4个数字是1,2,3,4,。 基于划分的解题思路 class Solution { public: vector<int> GetLeastNumbers_Solution(vector<int> input, int k) { i...

[LeetCode]470. Implement Rand10() Using Rand7()

rand7()生成rand10()

题目描述 Given a function rand7 which generates a uniform random integer in the range 1 to 7, write a function rand10 which generates a uniform random integer in the range 1 to 10. Do NOT use sy...

[C++基础]实现智能指针

智能指针

智能指针的实现 智能指针类将一个计数器与类指向的对象相关联,引用计数跟踪该类有多少个对象共享同一指针。 每次创建类的新对象时,初始化指针并将引用计数置为1; 当对象作为另一对象的副本而创建时,拷贝构造函数拷贝指针并增加与之相应的引用计数; 对一个对象进行赋值时,赋值操作符减少左操作数所指对象的引用计数(如果引用计数为减至0,则删除对象),并增加右操作数所指对象的引用计数; ...

[LeetCode]292. Nim Game

最后拿走石头的获胜

题目描述 You are playing the following Nim Game with your friend: There is a heap of stones on the table, each time one of you take turns to remove 1 to 3 stones. The one who removes the last stone ...