Skip to content

Commit 593f768

Browse files
committed
Added 1 solution & modified 1 solution
1 parent 43ada5a commit 593f768

File tree

2 files changed

+34
-16
lines changed

2 files changed

+34
-16
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
class Solution {
2+
public List<Integer> mostVisited(int n, int[] rounds) {
3+
List<Integer> list = new ArrayList<>();
4+
int from = rounds[0];
5+
int to = rounds[rounds.length - 1];
6+
if (to >= from) {
7+
for (int i = from; i <= to; i++) {
8+
list.add(i);
9+
}
10+
}
11+
else {
12+
for (int i = 1; i <= n; i++) {
13+
if (i == to + 1) {
14+
i = from;
15+
}
16+
list.add(i);
17+
}
18+
}
19+
return list;
20+
}
21+
}

Hard/Stream of Characters.java

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,15 @@ public StreamChecker(String[] words) {
55
root = new TrieNode('-');
66
stream = new ArrayDeque();
77
for (String word : words) {
8-
addWord(word);
9-
}
10-
}
11-
12-
private void addWord(String s) {
13-
TrieNode curr = root;
14-
for (int i = s.length() - 1; i >= 0; i--) {
15-
if (!curr.map.containsKey(s.charAt(i))) {
16-
curr.map.put(s.charAt(i), new TrieNode(s.charAt(i)));
8+
TrieNode curr = root;
9+
for (int i = word.length() - 1; i >= 0; i--) {
10+
if (!curr.map.containsKey(word.charAt(i))) {
11+
curr.map.put(word.charAt(i), new TrieNode(word.charAt(i)));
12+
}
13+
curr = curr.map.get(word.charAt(i));
1714
}
18-
curr = curr.map.get(s.charAt(i));
15+
curr.isWord = true;
1916
}
20-
curr.isWord = true;
2117
}
2218

2319
public boolean query(char letter) {
@@ -36,11 +32,6 @@ public boolean query(char letter) {
3632
}
3733
}
3834

39-
/**
40-
* Your StreamChecker object will be instantiated and called as such:
41-
* StreamChecker obj = new StreamChecker(words);
42-
* boolean param_1 = obj.query(letter);
43-
*/
4435

4536
class TrieNode {
4637
char c;
@@ -53,3 +44,9 @@ public TrieNode(char c) {
5344
isWord = false;
5445
}
5546
}
47+
48+
/**
49+
* Your StreamChecker object will be instantiated and called as such:
50+
* StreamChecker obj = new StreamChecker(words);
51+
* boolean param_1 = obj.query(letter);
52+
*/

0 commit comments

Comments
 (0)