Skip to content

Commit be4ebb1

Browse files
committed
Added 2 solutions
1 parent b7addcc commit be4ebb1

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
class Solution {
2+
public static String[] uncommonFromSentences(String A, String B) {
3+
Map<String, Long> map = Arrays.
4+
stream((A + " " + B).
5+
split("\\s+")).
6+
collect(Collectors.groupingBy(Function.identity(), Collectors.counting()));
7+
8+
List<String> uncommon = map.
9+
entrySet().
10+
stream().
11+
filter(e -> e.getValue() == 1).
12+
map(e -> e.getKey()).
13+
collect(Collectors.toList());
14+
15+
String[] ans = new String[uncommon.size()];
16+
17+
return uncommon.toArray(ans);
18+
}
19+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/**
2+
* Definition for a binary tree node.
3+
* public class TreeNode {
4+
* int val;
5+
* TreeNode left;
6+
* TreeNode right;
7+
* TreeNode(int x) { val = x; }
8+
* }
9+
*/
10+
class Solution {
11+
public TreeNode insertIntoBST(TreeNode root, int val) {
12+
if (root == null) {
13+
root = new TreeNode(val);
14+
return root;
15+
}
16+
17+
if (root.val < val) {
18+
root.right = insertIntoBST(root.right, val);
19+
}
20+
21+
if (root.val > val) {
22+
root.left = insertIntoBST(root.left, val);
23+
}
24+
25+
return root;
26+
}
27+
}

0 commit comments

Comments
 (0)