311. Sparse Matrix Multiplication
https://leetcode.com/problems/sparse-matrix-multiplication/description/
Last updated
Was this helpful?
https://leetcode.com/problems/sparse-matrix-multiplication/description/
Last updated
Was this helpful?
[] 如果给的是两个list分别代表两个vector, 每个list是根据index排好序的. 一种方法是依旧存到HashMap, 同样方法解 O(min(M, N)). 如果不让用hashmap, 就用两个指针从两个list头部开始往后遍历, 当list1的指向的index大就把list2的指针往前移动直到>=1的指针, 如果两个指针指向元素的index都相等, 就相乘加入结果. 时间复杂度O(M+N).