Find the K-Beauty of a Number LeetCode solution in C++
1class Solution {2public:3int divisorSubstrings(int num, int k) {4string str = to_string(num);5int i = 0, j = 0, n = str.length();6int ind = 0;78while (j < n) {9if (j - i + 1 < k) {10// increment j till we get the window size11++j;12} else if (j - i + 1 == k) {13// on hiting the window size14// extract window string and convert to int15// check if it follows the given condition16string s = str.substr(i, k);17int n = stoi(s);18if (n != 0 && num % n == 0) ++ind;1920// shift the window by ++j;21// remove previous calculation by ++i22++i;23++j;24}25}2627return ind;28}29};