Nth Natural Number | GeeksForGeeks | Problem of the Day

Поділитися
Вставка
  • Опубліковано 19 вер 2024

КОМЕНТАРІ • 4

  • @subhajitdey135
    @subhajitdey135 12 днів тому +1

    great explanation ;)

  • @mathematics3398
    @mathematics3398  13 днів тому

    Table of Contents
    0:00 Problem Statement
    0:39 Solution
    8:17 Pseudo Code
    10:06 Code - Python
    10:30 Code - C++

  • @mathematics3398
    @mathematics3398  13 днів тому

    class Solution:
    def findNth(self,n):
    ans = 0
    p = 1
    while n:
    ans += p*(n%9)
    n = n//9
    p *= 10
    return ans

  • @mathematics3398
    @mathematics3398  13 днів тому

    class Solution {
    public:
    long long findNth(long long n) {
    long long ans = 0;
    long long p = 1;
    while (n) {
    ans = ans + p*(n%9);
    n = n/9;
    p = p*10;
    }
    return ans;
    }
    };