Skip to content

Commit 0fb0a47

Browse files
authored
Add LeetCode 1299 solutions (Tahanima#59)
1 parent 69559d1 commit 0fb0a47

File tree

3 files changed

+40
-0
lines changed

3 files changed

+40
-0
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
class Solution {
2+
public:
3+
vector<int> replaceElements(vector<int>& arr) {
4+
int size = arr.size(), maxVal = -1;
5+
vector<int> answer (size, 0);
6+
7+
for (int i = size - 1; i >= 0; i--) {
8+
answer[i] = maxVal;
9+
maxVal = max(maxVal, arr[i]);
10+
}
11+
12+
return answer;
13+
}
14+
};
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
public class Solution {
2+
public int[] ReplaceElements(int[] arr) {
3+
int size = arr.Length, maxVal = -1;
4+
int[] answer = new int[size];
5+
6+
for (int i = size - 1; i >= 0; i--) {
7+
answer[i] = maxVal;
8+
maxVal = Math.Max(maxVal, arr[i]);
9+
}
10+
11+
return answer;
12+
}
13+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
class Solution {
2+
public int[] replaceElements(int[] arr) {
3+
int size = arr.length, maxVal = -1;
4+
int[] answer = new int[size];
5+
6+
for (int i = size - 1; i >= 0; i--) {
7+
answer[i] = maxVal;
8+
maxVal = Math.max(maxVal, arr[i]);
9+
}
10+
11+
return answer;
12+
}
13+
}

0 commit comments

Comments
 (0)