Skip to content

Commit c13ae65

Browse files
committed
Added 2 solutions & modified 1 solution
1 parent 16bff8a commit c13ae65

File tree

3 files changed

+55
-9
lines changed

3 files changed

+55
-9
lines changed

Easy/Armstrong Number.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
class Solution {
2+
public boolean isArmstrong(int N) {
3+
int n = getLength(N);
4+
return getNthPowerSum(N, n) == N;
5+
}
6+
7+
private int getNthPowerSum(int n, int p) {
8+
int sum = 0;
9+
while (n > 0) {
10+
int temp = n % 10;
11+
n /= 10;
12+
sum += (int) Math.pow(temp, p);
13+
}
14+
15+
return sum;
16+
}
17+
18+
private int getLength(int n) {
19+
int count = 0;
20+
while (n > 0) {
21+
n /= 10;
22+
count++;
23+
}
24+
25+
return count;
26+
}
27+
}

Easy/Largest Unique Number.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
class Solution {
2+
public int largestUniqueNumber(int[] A) {
3+
Map<Integer, Integer> map = new HashMap<>();
4+
for (int num : A) {
5+
map.put(num, map.getOrDefault(num, 0) + 1);
6+
}
7+
8+
int maxVal = Integer.MIN_VALUE;
9+
for (Integer key : map.keySet()) {
10+
if (map.get(key) == 1) {
11+
maxVal = Math.max(maxVal, key);
12+
}
13+
}
14+
15+
return maxVal == Integer.MIN_VALUE ? -1 : maxVal;
16+
}
17+
}

Medium/Teemo Attacking.java

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
class Solution {
22
public int findPoisonedDuration(int[] timeSeries, int duration) {
3+
if (duration == 0 || timeSeries.length == 0) {
4+
return 0;
5+
}
6+
7+
int totalTime = 0;
8+
int beginTime = timeSeries[0];
9+
for (int time : timeSeries) {
10+
totalTime += (time < beginTime + duration ? time - beginTime : duration);
11+
beginTime = time;
12+
}
313

4-
if (timeSeries.length == 0 || duration == 0) return 0;
5-
6-
int begin = timeSeries[0], total = 0;
7-
for (int t : timeSeries) {
8-
total = total + (t < begin + duration ? t - begin : duration);
9-
begin = t;
10-
}
11-
12-
return total + duration;
14+
return totalTime + duration;
1315
}
1416
}

0 commit comments

Comments
 (0)