• Skip to primary navigation
  • Skip to content
  • Skip to footer
zhicheng xie's demo blog
  • Quick-Start Guide

    Your Name

    I am an amazing person.

    • Somewhere

    Replace Elements with Greatest Element on Right Side

    less than 1 minute read

    <-E> Replace Elements with Greatest Element on Right Side

    class Solution {
    public:
        vector<int> replaceElements(vector<int>& arr) {
            int temp = -1;
            arr.push_back(-1);
            for(int i = arr.size() - 2; i >= 0; i--) {
                if(arr[i] > temp)
                    temp = arr[i];
                else
                    arr[i] = temp;
            }
            arr.erase(arr.begin());
            return arr;
        }
    };
    

    Tags: Algorithms, C++, Leetcode

    Updated: January 17, 2020

    Share on

    Twitter Facebook LinkedIn
    Previous Next

    You may also enjoy

    Decode Ways

    less than 1 minute read

    <-M 91> Decode Ways

    Word Break

    less than 1 minute read

    <-H 139> Word Break

    Distinct Subsequences

    less than 1 minute read

    <-H 115> Distinct Subsequences

    Edit Distance

    less than 1 minute read

    <-H 72> Edit Distance

    • Follow:
    • Feed
    © 2023 zhicheng xie's blog. Powered by Jekyll & Minimal Mistakes.