I started practicing on leetcode recently only. And from the first day, I was doubting the execution time it shows, because after submitting my code, I used to check the fastest executing code also and they also don't appear very different many times. Today, I submitted the solution to one of the problem 5 times, and guess what, every time it showed a different run time, varying from 11ms to 22ms. The problem is a very easy one. I am attaching my solution here, please let me know, how much time it take on your system.
Problem:
Easy: 867. Transpose Matrix
My Solution:
class Solution {
public:
vector<vector<int>> transpose(vector<vector<int>>& m1) {
int n = m1.size(), m = m1[0].size();
vector<vector<int>> m2(m, vector<int> (n));
for(int i = 0; i < n; i++)
for(int j = 0; j < m; j++)
m2[j][i] = m1[i][j];
return m2;
}
};