Skip to content

Latest commit

 

History

History
28 lines (23 loc) · 561 Bytes

furthestdistancefromorigin.md

File metadata and controls

28 lines (23 loc) · 561 Bytes

题目描述:

image

解决过程:

第360场周赛t1,不会做我靠,脑筋急转弯居然没有想出来

代码:

class Solution {
public:
    int furthestDistanceFromOrigin(string moves) {
        int pos = 0, len = 0;
        for (char c : moves) {
            if (c == 'L') {
                --pos;
            } else if (c == 'R') {
                ++pos;
            } else {
                ++len;
            }
        }
        return abs(pos) + len;
    }
};