Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit1ba9d39

Browse files
authored
Merge pull requestneetcode-gh#1241 from nehalalifayed/main
Create 1299-Replace-Elements-with-Greatest-Element-on-Right-Side.cpp
2 parents1426491 +1e8a8aa commit1ba9d39

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
classSolution {
2+
public:
3+
vector<int>replaceElements(vector<int>& arr) {
4+
// O(N) Time Complexity , O(1) Space complexity
5+
int n = arr.size();
6+
int maxSoFar = arr[n-1];
7+
arr[n-1] = -1;
8+
9+
for(int i=n-2;i>=0;i--)
10+
{
11+
int temp = maxSoFar;
12+
if(maxSoFar < arr[i]) maxSoFar = arr[i];
13+
arr[i] = temp;
14+
}
15+
return arr;
16+
}
17+
};

‎cpp/392-Is-Subsequence.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Time Complexity is O(N) where n is the size of the target string.
2+
// Space Complexity is O(1)
3+
4+
classSolution {
5+
public:
6+
boolisSubsequence(string s, string t) {
7+
int i =0 , j =0;
8+
while(j < s.size() && i < t.size())
9+
{
10+
if(s[j] == t[i])
11+
j++;
12+
13+
i++;
14+
}
15+
16+
if(j >= s.size())returntrue;
17+
returnfalse;
18+
}
19+
};

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp