Skip to content

Commit cf709d9

Browse files
add 816
1 parent e20244a commit cf709d9

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -468,6 +468,7 @@ _If you like this project, please leave me a star._ ★
468468
|821|[Shortest Distance to a Character](https://leetcode.com/problems/shortest-distance-to-a-character/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_821.java) | |Easy|
469469
|820|[Short Encoding of Words](https://leetcode.com/problems/short-encoding-of-words/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_820.java) | |Medium|
470470
|819|[Most Common Word](https://leetcode.com/problems/most-common-word/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_819.java) | |Easy| HashMap
471+
|816|[Ambiguous Coordinates](https://leetcode.com/problems/ambiguous-coordinates/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_816.java) | |Medium| String
471472
|814|[Binary Tree Pruning](https://leetcode.com/problems/binary-tree-pruning/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_814.java) | |Medium| recursion, DFS
472473
|811|[Subdomain Visit Count](https://leetcode.com/problems/subdomain-visit-count/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_811.java) | |Easy| HashMap
473474
|809|[Expressive Words](https://leetcode.com/problems/expressive-words/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_809.java) | |Medium|
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package com.fishercoder.solutions;
2+
3+
import java.util.ArrayList;
4+
import java.util.List;
5+
6+
public class _816 {
7+
public static class Solution1 {
8+
public List<String> ambiguousCoordinates(String s) {
9+
s = s.substring(1, s.length() - 1);
10+
List<String> list = new ArrayList<>();
11+
for (int i = 1; i < s.length(); i++) {
12+
String x = s.substring(0, i);
13+
List<String> xs = findAllPossibilities(x);
14+
String y = s.substring(i);
15+
List<String> ys = findAllPossibilities(y);
16+
for (String j : xs) {
17+
for (String k : ys) {
18+
list.add("(" + j + ", " + k + ")");
19+
}
20+
}
21+
}
22+
return list;
23+
}
24+
25+
private List<String> findAllPossibilities(String str) {
26+
List<String> result = new ArrayList<>();
27+
if (str.length() == 1) {
28+
result.add(str);
29+
return result;
30+
} else {
31+
for (int i = 1; i < str.length(); i++) {
32+
String integerPart = str.substring(0, i);
33+
String floatPart = str.substring(i);
34+
if (integerPart.length() > 1 && integerPart.charAt(0) != '0' && floatPart.charAt(floatPart.length() - 1) != '0') {
35+
result.add(integerPart + "." + floatPart);
36+
} else if (integerPart.length() == 1 && floatPart.charAt(floatPart.length() - 1) != '0') {
37+
result.add(integerPart + "." + floatPart);
38+
}
39+
}
40+
if (str.charAt(0) != '0') {
41+
result.add(str);
42+
}
43+
}
44+
return result;
45+
}
46+
}
47+
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy