예제 #1
0
 void twoSum(vector<int> &num, int i1, int i2, int target)
 {
     vector<int> vret(4);
     vret[0] = num[i1];
     vret[1] = num[i2];
     
     int low = i2 + 1;
     int high = num.size() - 1;
     
     while (low < high)
     {
         int sum = num[i1] + num[i2] + num[low] + num[high];
         
         if (sum == target)
         {
             vret[2] = num[low];
             vret[3] = num[high];
             
             vvnums.push_back(vret);
             
             while ((num[++low] == num[low-1]) && (low < high)) ;
             while ((num[--high] == num[high+1] && (low < high)));
         }
         else if (sum > target)
             --high;
         else
             ++low;
     }
     return;
 }
예제 #2
0
    void twoSum(vector<int> &num, int start, int target)
    {
        vector<int> vret(3);
        vret[0] = -target;

        int low = start;
        int high = num.size() - 1;

        while (low < high)
        {
            int sum = num[low] + num[high];
            if (sum == target)
            {
                vret[1] = num[low];
                vret[2] = num[high];
                vvsums.push_back(vret);

                //++low;
                //--high;

                while ((num[++low] == num[low-1]) && (low < high)) ;   // remove dups
                while ((num[--high] == num[high+1]) && (low < high));
            }
            else if (sum > target)
                --high;
            else
                ++low;
        }
        return;
    }
예제 #3
0
std::vector<uint> UnionFind::findIdxs(std::vector<uint> indices){
	std::set<uint> ret;
	for(uint i = 0; i < indices.size(); ++i){
		if(m_seen[indices[i]]){
			ret.insert(find(indices[i]));
		}
	}
	std::vector<uint> vret(ret.begin(), ret.end());
	return vret;
}
예제 #4
0
    std::vector<T*> instances() 
    {
        std::vector<T*> vret( this->instance_.begin(), this->instance_.end() );

        return vret;
    }