Leetcode-5039 Moving Stones Until Consecutive(移动石子直到连续)
1 class Solution 2 { 3 public: 4 vector<int> numMovesStones(int a, int b, int c) 5 { 6 vector<int> rnt(2,0); 7 vector<int> v; 8 v.push_back(a); 9 v.push_back(b); 10 v.push_back(c); 11 sort(v.begin(),v.end()); 12 if(v[0]==v[1]-1 && v[1]==v[2]-1) 13 return rnt; 14 15 rnt[1] = v[2]-v[1] + v[1]-v[0] -2; 16 if(v[0]==v[1]-1 || v[1]==v[2]-1 || v[0]==v[1]-2 || v[1]==v[2]-2) 17 rnt[0] = 1; 18 else 19 rnt[0] = 2; 20 return rnt; 21 } 22 };