leetcodeSolution to some Leetcode problems written in C++ |
git clone git://git.dimitrijedobrota.com/leetcode.git |
Log | Files | Refs | README | LICENSE |
2087.cpp (525B)
0 class Solution { 1 public: 2 int minCost(const vector<int> &startPos, const vector<int> &homePos, const vector<int> &rowCosts, 3 const vector<int> &colCosts) const { 4 int i = startPos[0], j = startPos[1]; 5 int x = homePos[0], y = homePos[1]; 6 int res = 0; 7 8 while (i != x) { 9 i += i < x ? 1 : -1; 10 res += rowCosts[i]; 11 } 12 13 while (j != y) { 14 j += j < y ? 1 : -1; 15 res += colCosts[j]; 16 } 17 18 return res; 19 } 20 };