Skip to content

Commit 53e20c6

Browse files
committed
Added 2 solutions
1 parent a836a86 commit 53e20c6

File tree

3 files changed

+36
-0
lines changed

3 files changed

+36
-0
lines changed

Easy/Make The String Great.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
class Solution {
2+
public String makeGood(String s) {
3+
Stack<Character> stack = new Stack<>();
4+
for (char c : s.toCharArray()) {
5+
if (!stack.isEmpty() && Math.abs(stack.peek() - c) == 32) {
6+
stack.pop();
7+
}
8+
else {
9+
stack.push(c);
10+
}
11+
}
12+
StringBuilder sb = new StringBuilder();
13+
while (!stack.isEmpty()) {
14+
sb.append(stack.pop());
15+
}
16+
return sb.reverse().toString();
17+
}
18+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
class Solution {
2+
public int maxNonOverlapping(int[] nums, int target) {
3+
int sum = 0;
4+
int count = 0;
5+
Map<Integer, Integer> map = new HashMap<>();
6+
map.put(0, -1);
7+
int lastIdx = -1;
8+
for (int i = 0; i < nums.length; i++) {
9+
sum += nums[i];
10+
if (map.containsKey(sum - target) && map.get(sum - target) >= lastIdx) {
11+
count++;
12+
lastIdx = i;
13+
}
14+
map.put(sum, i);
15+
}
16+
return count;
17+
}
18+
}
File renamed without changes.

0 commit comments

Comments
 (0)