class Solution {
public int calculate(String s) {
int x = 1;
int y = 0;
for (int i = 0; i < s.length(); i++) {
if (s.charAt(i) == 'A') x = 2 * x + y;
if (s.charAt(i) == 'B') y = 2 * y + x;
}
return x + y;
}
}
leetcode LCP 17. 速算机器人
最新推荐文章于 2025-05-12 00:04:39 发布