Skip to content

Commit dd85338

Browse files
committed
Added 3 medium solutions
1 parent 284b1fa commit dd85338

File tree

3 files changed

+55
-0
lines changed

3 files changed

+55
-0
lines changed

Medium/Arithmetic Slices.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
class Solution {
2+
public int numberOfArithmeticSlices(int[] A) {
3+
4+
int curr = 0, sum = 0;
5+
for (int i=2; i<A.length; i++)
6+
if (A[i]-A[i-1] == A[i-1]-A[i-2]) {
7+
curr += 1;
8+
sum += curr;
9+
}
10+
else {
11+
curr = 0;
12+
}
13+
14+
return sum;
15+
}
16+
}

Medium/Palindromic Substrings.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
class Solution {
2+
public int countSubstrings(String s) {
3+
int count = 0;
4+
for (int i=0;i<s.length();i++) {
5+
for (int j=i;j<s.length();j++) {
6+
if(isPalindrome(s.substring(i,j+1))) {
7+
count++;
8+
}
9+
}
10+
}
11+
12+
return count;
13+
}
14+
15+
public boolean isPalindrome(String s) {
16+
StringBuilder sb = new StringBuilder("");
17+
sb.append(s);
18+
return sb.reverse().toString().equals(s);
19+
}
20+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
class Solution {
2+
public int[][] reconstructQueue(int[][] people) {
3+
4+
Arrays.sort(people,new Comparator<int[]>(){
5+
@Override
6+
public int compare(int[] o1, int[] o2){
7+
return o1[0]!=o2[0]?-o1[0]+o2[0]:o1[1]-o2[1];
8+
}
9+
});
10+
11+
List<int[]> res = new LinkedList<>();
12+
for(int[] cur : people){
13+
res.add(cur[1],cur);
14+
}
15+
16+
return res.toArray(new int[people.length][]);
17+
18+
}
19+
}

0 commit comments

Comments
 (0)