最近刷题进展尚可,但是形式变化了下,因为感觉眼睛会看瞎,所以好多写在纸上。本来想放到文件夹存储起来,但是太容易丢了,明天整理下,赶紧拍上来把
今晚是周末,这一周都在不停的学学学,我想下周怕是不能睡午觉了,中午回去床对我的诱惑太大了,我得想办法,一进门先把被褥收起来,再放个欢快的歌,中午少吃点,加油小可爱
Given two words (beginWord and endWord), and a dictionary‘s word list, find all shortest transformation sequence(s) from beginWord to endWord, such that:
Note:
Example 1:
Input: beginWord = "hit", endWord = "cog", wordList = ["hot","dot","dog","lot","log","cog"] Output: [ ["hit","hot","dot","dog","cog"], ["hit","hot","lot","log","cog"] ]
Example 2:
Input: beginWord = "hit" endWord = "cog" wordList = ["hot","dot","dog","lot","log"] Output: [] Explanation: The endWord "cog" is not in wordList, therefore no possible transformation.
向量容器(vector)是一种顺序容器,是一块连续分配的内存,支持随机访问,从数据安排的角度看,和数组极其相似,数组跟vector的区别在于:数组是静态分配空间,一旦分配了空间的大小,就不可以再改变了,例如,int a[6];而vector是动态分配内存,随着元素的不断插入,它会按照自身的一套机制不断扩充自身的容量,vector容器的容量增长是按照容器现在容量的一倍进行增长。
begin函数:
函数原型:
iterator begin();
const_iterator begin();
功能:
返回一个当前vector容器中起始元素的迭代器。
end函数:
函数原型:
iterator end();
const_iterator end();
功能:
返回一个当前vector容器中末尾元素的迭代器。
front函数:
函数原型:
reference front();
const_reference front();
功能:
返回当前vector容器中起始元素的引用。
back函数:
函数原型:
reference back();
const_reference back();
功能:
返回当前vector容器中末尾元素的引用。
————————————————
版权声明:本文为CSDN博主「LzyRapX」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/liangzhaoyang1/article/details/51853686
2.
C++中的swap函数:交换函数
好处:不用担心交换变量精度的缺失,无需构造临时变量,不会增加空间复杂度
Given an unsorted array of integers, find the length of the longest consecutive elements sequence.
Your algorithm should run in O(n) complexity.
Example:
Input: [100, 4, 200, 1, 3, 2] Output: 4 Explanation: The longest consecutive elements sequence is[1, 2, 3, 4]
. Therefore its length is 4.
BONUS:
auto自动类型推断,用于从初始化表达式中推断出变量的数据类型。通过auto的自动类型推断,可以大大简化我们的编程工作。下面是一些使用auto的例子。
class Solution { public: int longestConsecutive(vector<int>& nums) { unordered_map<int,int> h; int ans=0; for(int num:nums){ if(h.count(num)) continue; //check whether can find iterator auto it_l=h.find(num-1); auto it_r=h.find(num+1); int l=it_l!=h.end()?it_l->second:0; int r=it_r!=h.end()?it_r->second:0; int t=l+r+1; h[num]=h[num-l]=h[num+r]=t; ans=max(ans,t); } return ans; } };
LeetCode开心刷题五十六天——128. Longest Consecutive Sequence
原文:https://www.cnblogs.com/Marigolci/p/12046855.html