Skip to content

Commit b8d95ef

Browse files
committed
Add solutions for problems 771, 1108, 1470, 1512, 1672, 1689, 1769, 1929, 2011, 2044, 2469, 2807, 2942, 3190, and 3467
1 parent 79ba3f3 commit b8d95ef

File tree

15 files changed

+367
-0
lines changed

15 files changed

+367
-0
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package me.darksnakex.problems;
2+
3+
public class p1108 {
4+
5+
public String defangIPaddr(String address) {
6+
return address.replaceAll("\\.", "[.]");
7+
}
8+
9+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package me.darksnakex.problems;
2+
3+
public class p1470 {
4+
5+
public int[] shuffle(int[] nums, int n) {
6+
7+
int[] arr = new int[nums.length];
8+
9+
int m = 0;
10+
for(int i = 0; i < arr.length; i+=2){
11+
arr[i] = nums[m];
12+
arr[i+1] = nums[n];
13+
m++;
14+
n++;
15+
}
16+
17+
return arr;
18+
}
19+
20+
21+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package me.darksnakex.problems;
2+
3+
public class p1512 {
4+
5+
public int numIdenticalPairs(int[] nums) {
6+
7+
int res = 0;
8+
for(int i = 0; i < nums.length; i++){
9+
int actual = nums[i];
10+
for (int j = 0; j < nums.length; j++){
11+
if(i < j && actual == nums[j]){
12+
res++;
13+
}
14+
}
15+
}
16+
17+
18+
return res;
19+
20+
}
21+
}
22+
23+
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package me.darksnakex.problems;
2+
3+
public class p1672 {
4+
5+
public int maximumWealth(int[][] accounts) {
6+
7+
int actual = 0;
8+
int max = 0;
9+
10+
for(int i = 0; i < accounts.length; i++){
11+
for(int j = 0; j < accounts[i].length; j++){
12+
actual+=accounts[i][j];
13+
}
14+
if(actual > max){
15+
max = actual;
16+
}
17+
actual = 0;
18+
}
19+
20+
21+
22+
return max;
23+
24+
}
25+
26+
27+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package me.darksnakex.problems;
2+
3+
public class p1689 {
4+
5+
6+
public int minPartitions(String n) {
7+
8+
int actual = -1;
9+
10+
for(int i = 0; i<n.length(); i++){
11+
if(actual < n.charAt(i)){
12+
actual = n.charAt(i);
13+
}
14+
}
15+
16+
for(char car: n.toCharArray()){
17+
if(actual < car){
18+
actual = car;
19+
}
20+
21+
}
22+
23+
return actual-48;
24+
}
25+
26+
public int minPartitionsold(String n){
27+
28+
int actual = -1;
29+
30+
for(int i = 0; i<n.length(); i++){
31+
if(actual < n.charAt(i)){
32+
actual = n.charAt(i);
33+
}
34+
}
35+
36+
return actual-48;
37+
38+
}
39+
40+
41+
}
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 p1769 {
4+
5+
public int[] minOperations(String boxes) {
6+
7+
8+
int[] res = new int[boxes.length()];
9+
10+
for(int i = 0; i < boxes.length(); i++){
11+
if(boxes.charAt(i) == '1') {
12+
for (int j = 0; j < boxes.length(); j++) {
13+
res[j] += Math.abs(i - j);
14+
}
15+
}
16+
}
17+
18+
19+
return res;
20+
21+
}
22+
}
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+
4+
public class p1929 {
5+
6+
public int[] getConcatenation(int[] nums) {
7+
8+
9+
int[] res = new int[nums.length + nums.length];
10+
int i = 0;
11+
int j = 0;
12+
while (j < nums.length + nums.length){
13+
for (int num : nums) {
14+
res[i] = num;
15+
j++;
16+
i++;
17+
}
18+
19+
}
20+
return res;
21+
}
22+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package me.darksnakex.problems;
2+
3+
import java.util.Collections;
4+
import java.util.List;
5+
6+
public class p2011 {
7+
8+
9+
public int finalValueAfterOperations(String[] operations) {
10+
int x = 0;
11+
for (String operation : operations) {
12+
if (operation.equals("X++") || operation.equals("++X")) {
13+
x += 1;
14+
} else {
15+
x -= 1;
16+
}
17+
18+
}
19+
20+
return x;
21+
22+
}
23+
24+
// Not that well lmao
25+
public int finalValueAfterOperationsv2(String[] operations) {
26+
List<String> list = List.of(operations);
27+
return Collections.frequency(list,"X++") + Collections.frequency(list,"++X") - Collections.frequency(list,"X--") -Collections.frequency(list,"--X");
28+
29+
}
30+
31+
32+
33+
}
34+
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 p2044 {
4+
5+
6+
7+
8+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package me.darksnakex.problems;
2+
3+
public class p2469 {
4+
5+
public double[] convertTemperature(double celsius) {
6+
7+
return new double[]{celsius+273.15,celsius*1.80 +32.00};
8+
9+
}
10+
11+
}

0 commit comments

Comments
 (0)