classSolution{public:vector<vector<int>>intervalIntersection(vector<vector<int>>&firstList,vector<vector<int>>&secondList){vector<vector<int>>ans;shorti=0;shortj=0;while(i<firstList.size()&&j<secondList.size()){// Lo := the start of the intersection// Hi := the end of the intersectionconstintlo=max(firstList[i][0],secondList[j][0]);constinthi=min(firstList[i][1],secondList[j][1]);if(lo<=hi)ans.push_back({lo,hi});firstList[i][1]<secondList[j][1]?++i:++j;}returnans;}};
classSolution{publicint[][]intervalIntersection(int[][]firstList,int[][]secondList){List<int[]>ans=newArrayList<>();shorti=0;shortj=0;while(i<firstList.length&&j<secondList.length){// Lo := the start of the intersection// Hi := the end of the intersectionfinalintlo=Math.max(firstList[i][0],secondList[j][0]);finalinthi=Math.min(firstList[i][1],secondList[j][1]);if(lo<=hi)ans.add(newint[]{lo,hi});if(firstList[i][1]<secondList[j][1])++i;else++j;}returnans.toArray(newint[ans.size()][]);}}
classSolution:defintervalIntersection(self,firstList:List[List[int]],secondList:List[List[int]])->List[List[int]]:ans=[]i=0j=0whilei<len(firstList)andj<len(secondList):# Lo := the start of the intersection# Hi := the end of the intersectionlo=max(firstList[i][0],secondList[j][0])hi=min(firstList[i][1],secondList[j][1])iflo<=hi:ans.append([lo,hi])iffirstList[i][1]<secondList[j][1]:i+=1else:j+=1returnans