2833. Furthest Point From Origin
/**
* Problem: LeetCode 2833 - Furthest Point From Origin
* Difficulty: Easy
* Language: Java
* Author: CodeByTushu
*/
class Solution {
public int furthestDistanceFromOrigin(String moves) {
int countL = 0;
int countR = 0;
int countBlank = 0;
int n = moves.length();
for (int i = 0; i < n; i++) {
char c = moves.charAt(i);
if (c == 'L') {
countL++;
} else if (c == 'R') {
countR++;
} else {
countBlank++;
}
}
return Math.abs(countL - countR) + countBlank;
}
}
"""
Problem: LeetCode 2833 - Furthest Point From Origin
Difficulty: Easy
Language: Python
Author: CodeByTushu
"""
class Solution:
def furthestDistanceFromOrigin(self, moves: str) -> int:
count_l = moves.count('L')
count_r = moves.count('R')
count_blank = moves.count('_')
return abs(count_l - count_r) + count_blank
/**
* Problem: LeetCode 2833 - Furthest Point From Origin
* Difficulty: Easy
* Language: C++
* Author: CodeByTushu
*/
#include <string>
#include <cmath>
using namespace std;
class Solution {
public:
int furthestDistanceFromOrigin(string moves) {
int countL = 0;
int countR = 0;
int countBlank = 0;
for (char c : moves) {
if (c == 'L') {
countL++;
} else if (c == 'R') {
countR++;
} else {
countBlank++;
}
}
return abs(countL - countR) + countBlank;
}
};
/**
* Problem: LeetCode 2833 - Furthest Point From Origin
* Difficulty: Easy
* Language: JavaScript
* Author: CodeByTushu
*/
/**
* @param {string} moves
* @return {number}
*/
var furthestDistanceFromOrigin = function(moves) {
let countL = 0;
let countR = 0;
let countBlank = 0;
for (let i = 0; i < moves.length; i++) {
const c = moves.charCodeAt(i);
if (c === 76) { // 'L'
countL++;
} else if (c === 82) { // 'R'
countR++;
} else { // '_'
countBlank++;
}
}
return Math.abs(countL - countR) + countBlank;
};