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

3917. Count Indices With Opposite Parity (Brute Force) O(n2) + Optimized Solution O(n) + tips LEETCODE WEEKLY 500

  class Solution {     public int [] countOppositeParity ( int [] nums ) {          // approach 1 - checks every pair         int n = n...