Straight-forward C++


  • 0
    T
    vector<vector<int>> multiply(vector<vector<int>>& A, vector<vector<int>>& B) {
            
            if(A.empty() || B.empty() || A[0].empty() || B[0].empty())
                return {{}};
    
            std::vector<std::vector<int>> res(A.size(),std::vector<int>(B[0].size(),0));
    
            for(int i=0; i<A.size(); ++i){
                for(int j=0; j<B[0].size(); ++j){
                    for(int k=0; k<B.size(); ++k){
                        if(!A[i][k] || !B[k][j])
                            continue;
                        res[i][j] += A[i][k] * B[k][j];
                    }
                }
            }
            return res;
        }
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.