Skip to content

Commit 69ac383

Browse files
solves #2833: Furthest Point From Origin in jaav
1 parent 5b6ebaf commit 69ac383

3 files changed

+28
-1
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -850,7 +850,7 @@
850850
| 2815 | [Max Pair Sum in an Array](https://leetcode.com/problems/max-pair-sum-in-an-array) | [![Java](assets/java.png)](src/MaxPairSumInAnArray.java) | |
851851
| 2824 | [Count Pairs Whose Sum is Less than Target](https://leetcode.com/problems/count-pairs-whose-sum-is-less-than-target) | [![Java](assets/java.png)](src/CountPairsWhoseSumIsLessThanTarget.java) | |
852852
| 2828 | [Check if a String Is an Acronym of Words](https://leetcode.com/problems/check-if-a-string-is-an-acronym-of-words) | [![Java](assets/java.png)](src/CheckIfAStringIsAnAcronymOfWords.java) | |
853-
| 2833 | [Furthest Point From Origin](https://leetcode.com/problems/furthest-point-from-origin) | | |
853+
| 2833 | [Furthest Point From Origin](https://leetcode.com/problems/furthest-point-from-origin) | [![Java](assets/java.png)](src/FurthestPointFromOrigin.java) | |
854854
| 2839 | [Check if Strings Can be Made Equal With Operations I](https://leetcode.com/problems/check-if-strings-can-be-made-equal-with-operations-i) | | |
855855
| 2843 | [Count Symmetric Integers](https://leetcode.com/problems/count-symmetric-integers) | | |
856856
| 2848 | [Points That Intersect With Cars](https://leetcode.com/problems/points-that-intersect-with-cars) | | |

src/FurthestPointFromOrigin.java

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// https://leetcode.com/problems/furthest-point-from-origin
2+
// T: O(N)
3+
// S: O(1)
4+
5+
public class FurthestPointFromOrigin {
6+
public int furthestDistanceFromOrigin(String moves) {
7+
final int numberOfLeftMoves = numberOf(moves, 'L');
8+
final int numberOfRightMoves = numberOf(moves, 'R');
9+
final int numberOfFreeMoves = numberOf(moves, '_');
10+
11+
return Math.abs(numberOfLeftMoves - numberOfRightMoves) + numberOfFreeMoves;
12+
}
13+
14+
private static int numberOf(final String moves, final char c) {
15+
int count = 0;
16+
for (int i = 0 ; i < moves.length() ; i++) {
17+
if (moves.charAt(i) == c) {
18+
count++;
19+
}
20+
}
21+
return count;
22+
}
23+
}

src/WidestVerticalAreaBetweenTwoPointsContainingNoPoints.java

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
// https://leetcode.com/problems/widest-vertical-area-between-two-points-containing-no-points
2+
// T: O(N log(N))
3+
// S: O(log(N))
4+
15
import java.util.Arrays;
26
import java.util.Comparator;
37

0 commit comments

Comments
 (0)