Created
April 30, 2021 11:57
-
-
Save vrat28/a1c0870289c934e2932a73a821fc9681 to your computer and use it in GitHub Desktop.
Powerful Integers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Solution { | |
func powerfulIntegers(_ x: Int, _ y: Int, _ bound: Int) -> [Int] { | |
guard bound >= 2 else{ | |
return [] | |
} | |
var set = Set<Int>() | |
var powerX = 1 | |
for i in 1..<bound where powerX <= bound{ | |
var powerY = 1 | |
while powerX + powerY <= bound { | |
set.insert(powerX + powerY) | |
powerY *= y | |
if y == 1 { | |
break | |
} | |
} | |
if x == 1 { | |
break | |
} | |
powerX *= x | |
} | |
return Array(set) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment