![](https://img-blog.csdnimg.cn/20201014180756780.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
Data Manipulation
Chen_chish
这个作者很懒,什么都没留下…
展开
-
[Leetcode]Longest Consecutive Sequence
思路:要求O(N),无法使用排序,一般都需要用到哈希。我们现在遍历输入元素的时候,如果可以很快的找到其前一个和后一个数(对于3来说是2和4),那么我们只要向前和向后遍历即可,为了防止重复遍历可以标记已经访问过的元素。class Solution {public: int longestConsecutive(vector &num) { // Start typing原创 2013-06-20 10:04:25 · 378 阅读 · 0 评论 -
[Leetcode]Best Time to Buy and Sell Stock
思路:Find i and j that maximizes Aj - Ai, where i 显然有O(N^2)的方法,我们可以找到O(N)的算法,就是记录当前扫描过的数据中的最小值。class Solution {public: int maxProfit(vector &prices) { // Start typing your C/C++ solutio原创 2013-06-20 15:09:16 · 469 阅读 · 0 评论 -
[剑指offer]用两个栈实现队列
思路:一个栈用来入队,另外一个栈用来出队#include #include #include #include #include using namespace std;int main(){ int n; while(cin>>n) { stack input, output; for(int i = 0; i < n; ++i) { string c原创 2013-06-25 17:06:30 · 334 阅读 · 0 评论