Skip to content

Commit 5d2dfcd

Browse files
committed
Add solutions for problems 1920, 2769, 2894, and 3110
1 parent eef0256 commit 5d2dfcd

File tree

4 files changed

+67
-0
lines changed

4 files changed

+67
-0
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package me.darksnakex.problems;
2+
3+
public class p1920 {
4+
5+
6+
public int[] buildArray(int[] nums) {
7+
int[] res = new int[nums.length];
8+
9+
for(int i = 0; i < nums.length; i++){
10+
res[i]=nums[nums[i]];
11+
}
12+
13+
return res;
14+
}
15+
16+
17+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package me.darksnakex.problems;
2+
3+
public class p2769 {
4+
5+
public int theMaximumAchievableX(int num, int t) {
6+
return num+t+t;
7+
}
8+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package me.darksnakex.problems;
2+
3+
public class p2894 {
4+
5+
public int differenceOfSums(int n, int m) {
6+
int res1 = 0;
7+
int res2 = 0;
8+
9+
for(int i = 1; i <= n; i++){
10+
if(i % m == 0){
11+
res1+=i;
12+
}else{
13+
res2+=i;
14+
}
15+
16+
}
17+
18+
return res2-res1;
19+
20+
}
21+
22+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package me.darksnakex.problems;
2+
3+
public class p3110 {
4+
5+
public int scoreOfString(String s) {
6+
int res = 0;
7+
int anterior = 0;
8+
9+
char[] charArray = s.toCharArray();
10+
11+
for(char car: charArray){
12+
if(anterior != 0) {
13+
res += Math.abs(car - anterior);
14+
}
15+
anterior = car;
16+
}
17+
18+
return res;
19+
}
20+
}

0 commit comments

Comments
 (0)