Ash914027 / leetcodeproblem

leetcode with problrm:LeetCode Solutions Repository This repository contains solutions to various LeetCode problems implemented in C++ and Java. The project aims to provide efficient and optimized solutions to coding challenges on the popular online coding platform, LeetCode
0 stars 7 forks source link

Create lexicographical-numbers.cpp #2

Closed DevanshuB211 closed 1 month ago

DevanshuB211 commented 1 month ago

Approach: 1.Start at curr = 1. 2.In each iteration, add curr to the result. 3.If curr * 10 <= n, move to the next lexicographical number by multiplying curr by 10. 4.Otherwise, if curr is too large or reaches n, backtrack by dividing by 10 and incrementing curr. 5.Repeat until all numbers from 1 to n are covered.