LC 1952. Three Divisors

Nilanjan Deb · August 2, 2021

This is my CPP solution.

class Solution {
public:
    bool isThree(int n) {
        int count = 0;
        int currNum = 1;

        while(currNum <= n) {
            if(n%currNum == 0) {
                count++;
            }
            currNum++;
            if(count>3) {
                return false;
            }
        }

        if(count == 3) return true;
        return false;
    }
};


Dicussion Forum