Skip to content

Instantly share code, notes, and snippets.

class Solution {
public int numFactoredBinaryTrees(int[] A) {
int MOD = 1000000007;
int n = A.length;
Arrays.sort(A);
long[] dp = new long[n];
Arrays.fill(dp, 1);
Map<Integer, Integer> map = new HashMap<>();
for (int i = 0; i < n; i++) {
class Solution {
public int flipgame(int[] fronts, int[] backs) {
Set<Integer> same = new HashSet<>();
int n = fronts.length;
for (int i = 0; i < n; i++) {
if (fronts[i] == backs[i]) {
same.add(fronts[i]);
}
}
class TrieNode {
TrieNode[] children;
int count;
TrieNode () {
children = new TrieNode[26];
count = 0;
}
TrieNode insert (String w, int idx) {
if (idx == -1) {
class Solution {
public int[] shortestToChar(String S, char C) {
int n = S.length();
int[] res = new int[n];
int pre = Integer.MIN_VALUE / 2;
for (int i = 0; i < n; i++) {
if (S.charAt(i) == C) {
pre = i;
}
class UF {
public int count = 0;
public int[] id = null;
public int[] size = null;
public UF(int m, int n, int[][] grid) {
id = new int[m * n];
size = new int[m * n];
class Solution {
class Task {
int d;
int p;
Task(int d, int p) {
this.d = d;
this.p = p;
}
}
public int maxProfitAssignment(int[] difficulty, int[] profit, int[] worker) {
class Solution {
public int numFriendRequests(int[] ages) {
int n = ages.length;
int res = 0;
Arrays.sort(ages);
int start = 0, end = 0;
while (end < n) {
if (start == end) end++;
if (ages[start] * 1.0 > ages[end] * 0.5 + 7.0) {
class Solution {
String vowels = "aeiouAEIOU";
public String toGoatLatin(String S) {
if (S == null || S.length() == 0) return "";
StringBuilder sb = new StringBuilder();
String[] words = S.split(" ");
for (int i = 0; i < words.length; i++) {
String cur = words[i];
if (vowels.contains(cur.charAt(0) + "")) {
sb.append(cur);
import java.util.*;
class Solution {
public String similarRGB(String color) {
StringBuilder sb = new StringBuilder();
sb.append('#');
for (int i = 1; i < 7; i += 2) {
sb.append(getHexadecimal(color.charAt(i), color.charAt(i + 1)));
}
return sb.toString();
import java.util.*;
class Solution {
class carInfo {
int pos;
int speed;
carInfo(int pos, int speed) {
this.pos = pos;
this.speed = speed;
}
}