J.P. Morgan Interview Question

Leet code question 263 ugly numbers

Interview Answers

Anonymous

Jan 7, 2023

class Solution { public: bool isUgly(int n) { if (n 1) { if (n % 2 == 0) n = n / 2; else if (n % 3 == 0) n = n / 3; else if (n % 5 == 0) n = n / 5; else break; } return (n == 1); } };

4

Anonymous

Jan 7, 2023

class Solution { public: bool isUgly(int n) { if (n 1) { if (n % 2 == 0) n = n / 2; else if (n % 3 == 0) n = n / 3; else if (n % 5 == 0) n = n / 5; else break; } return (n == 1); } };

1