Pages

Monday, April 21, 2025

Reverse of an Array in C++

 #include <iostream>

#include <cstring>

using namespace std;


void reverse(char word[], int n) {

    int st = 0, end = n-1;

    while(st < end) {

        swap(word[st], word[end]);

        st++;

        end--;

    }

}


int main()

{

    char word[] = "code";

    reverse(word, strlen(word));

    

    cout << "reverse = " << word << endl;


    return 0;

}

No comments:

Post a Comment

3917. Count Indices With Opposite Parity (Brute Force) O(n2) + Optimized Solution O(n) + tips LEETCODE WEEKLY 500

  class Solution {     public int [] countOppositeParity ( int [] nums ) {          // approach 1 - checks every pair         int n = n...