2833. Furthest Point From Origin 發表於 2023-12-21 | 分類於 leetcode problemsolution12345678910111213141516class Solution {public: int furthestDistanceFromOrigin(string moves) { int lcount = 0, rcount =0, count = 0 ; for(char c:moves) { if(c=='L' || c=='_') lcount++; if(c=='R' || c=='_') rcount++; if(c=='_') count++; } if(lcount > rcount) rcount-=count; else lcount-=count; return abs(lcount - rcount); }}; analysis time complexity O(n) space complexity O(1)