Automatart Lab's coding practise

This is Automatart Lab's coding practise blog.

Divide Two Integers - LeetCode

Divide two integers without using multiplication, division and mod operator. This is my solution, written in C++:

class Solution {
public:
    int divide(int Dividend, int Divisor) {
        int uno;
        uno=1;
        int cachitosDividendo [Dividend];
        int cachitosDivisor [Divisor];
        int suma;
        suma=0;
        
        for (int i=0; i<Dividend; i++) {
            cachitosDividendo[i]=uno;
        }
        
        for (int i=0; i<Divisor; i++) {
            cachitosDivisor[i]=uno;
        }
        
        for (int i=0; i<Divisor; i++) {
            suma=suma+cachitosDividendo[i];
        }
        
        return suma;
        
    }
};

Longest Consecutive Sequence - LeetCode

Given an unsorted array of integers, find the length of the longest consecutive elements sequence.

This is my O(n) solution, written in C++:

class Solution {
public:
    int longestConsecutive(vector<int> &num) {
        
        int min;
        int length;
        
        if (num.size() == 0) {
            return 0;                 
        }
        
        min=num[0];
        
        for (int i=0; i<num.size(); i++) {
            if (num[i]<min) {
                min = num[i];            
            }
        }
        
        length=1;
       
        for (int i=0; i<num.size(); i++) {
            if(std::find(num.begin(), num.end(), min)!=num.end()) {             
                if(std::find(num.begin(), num.end(), min+1)!=num.end()) {      
                    min=min+1;         
                    length++;           
                }
            }
        }
        return length;
    }
};

tumblrbot asked: WHAT MAKES YOU FEEL BETTER WHEN YOU ARE IN A BAD MOOD?

Singgggggggggggg