Weekly Contest
限制 :
1 <= moves.length == n <= 50
moves consists only of characters 'L', 'R' and '_'
就是簡單的計算哪邊數字大,相減之後再加上底線的數量即為答案。
程式碼:
class Solution { public: int furthestDistanceFromOrigin(string moves) { int num_R = 0, num_L = 0, num_S = 0; for(int i=0; i < moves.size();i++) { switch(moves[i]) { case 'L': num_L++; break; case 'R': num_R++; break; case '_': num_S++; break; } } return max(num_R, num_L) + num_S - min(num_R, num_L); } };
1 <= n <= 109
1 <= target <= 109
104
or
By clicking below, you agree to our terms of service.
New to HackMD? Sign up