-1
class Solution {
public:
    vector<vector<int>> merge(vector<vector<int>>& intervals) {
    
        //Returned Vector
        vector<vector<int>> mergedIntervals;
        
        //If the array size is 0 return Null array
        if(intervals.size()==0){
            return mergedIntervals;
        }
        
        //sort the array
        sort(intervals.begin(),intervals.end());
        
        //Insert the first set in the array tempIntervals i.e [start,end]
        vector<int> tempInterval =intervals[0];
        
        //Iterate in the array
        for(auto it:intervals){
        
            //if (second of last set) is greater than (first of current set)
            //means they are merging intervals
            if(it[0]<=tempInterval[1]){   <<<<<<<<<<<<<<<------------ please can anyone explain this line
            
                //so change the end limit of the merge set 
                tempInterval[1]=max(it[1],tempInterval[1]);
                
            }else{
            
                //if they are not merging then simply push previous set 
                //in the Returned vector
                mergedIntervals.push_back(tempInterval);
                
                //assign the current set 
                tempInterval=it;
            }
        }
        
        //Insert the last set left in the tempInterval inside the return array
        mergedIntervals.push_back(tempInterval);
        
        return mergedIntervals;
    }
};

please anyone explain me this line it[0] containing what and does tempInterval[1] means tempInterval[0][1]

273K
  • 29,503
  • 10
  • 41
  • 64
  • If you want to learn C++, don't use Leetcode (or any other competitive site including geekforgeeks.com) use : [a recent C++ book](https://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list) or from [learncpp.com](https://www.learncpp.com/) that site is decent and pretty up to date. Then use [cppreference](https://en.cppreference.com/w/) for reference material (and examples). When you have done all that keep using [C++ core guidelines](https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines) to keep up to date with the latest best practices since C++ keeps evolving. – Pepijn Kramer Apr 26 '23 at 04:22

1 Answers1

0

(Welcome to Stack Overflow.)

intervals is a reference to a vector<vector<int>>.

it is an element of intervals, therefore it is a vector<int>.

it[0] is the first element of it, therefore it is an int.

tempInterval is a vector<int>. tempInterval[1] makes sense, temInterval[0][1] does not, and the two are definitely not the same thing.

Beta
  • 96,650
  • 16
  • 149
  • 150