leetcode

Solution to some Leetcode problems written in C++
git clone git://git.dimitrijedobrota.com/leetcode.git
Log | Files | Refs | README | LICENSE

1424.cpp (568B)


      1 class Solution {
      2     typedef tuple<int, int, int> rec_t;
      3 
      4   public:
      5     vector<int> findDiagonalOrder(const vector<vector<int>> &nums) const {
      6         static rec_t arr[100001];
      7         int n = 0;
      8         for (int i = 0; i < nums.size(); i++) {
      9             for (int j = 0; j < nums[i].size(); j++) {
     10                 arr[n++] = {-i - j, i, nums[i][j]};
     11             }
     12         }
     13         sort(begin(arr), begin(arr) + n, greater<rec_t>());
     14         vector<int> res;
     15         for (int i = 0; i < n; i++)
     16             res.push_back(get<2>(arr[i]));
     17         return res;
     18     }
     19 };