参考后
class Solution {
public:int longestConsecutive(vector<int>& nums) {unordered_set<int> st(cbegin(nums), cend(nums));int ret = 0;while (!st.empty()) {int num = *begin(st);int forward = num;int backward = num;int len = 1;st.erase(num);// seak forwardunordered_set<int>::iterator it;while ((it = st.find(--forward)) != cend(st)) {++len;st.erase(it);}while ((it = st.find(++backward)) != cend(st)) {++len;st.erase(it);}ret = max(ret, len);}return ret;}
};