Pages

Saturday, April 26, 2025

2D Array Vectors in C++

 #include <iostream>

#include <vector>

using namespace std;


int main()


{

    vector <vector<int>> matrix = {

        {1,2, 3}, 

        {4, 5, 6},  // can make it {4, 5}

        {7, 8, 9}   // can make it {6}

    };


    for(int i=0; i<matrix.size(); i++) {

        for(int j=0; j<matrix[i].size(); j++) {

            cout << matrix[i][j] << " ";

            

        }

        

        cout << endl;

    }

    

    return 0;

}

No comments:

Post a Comment

remove duplicates from sorted array - two pointer approach (leetcode)

  class Solution {     public int removeDuplicates ( int [] nums ) {         // base case: return if array have no el.         if ( nums...