Skip to content

Instantly share code, notes, and snippets.

@vrat28
Created April 30, 2021 11:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vrat28/a1c0870289c934e2932a73a821fc9681 to your computer and use it in GitHub Desktop.
Save vrat28/a1c0870289c934e2932a73a821fc9681 to your computer and use it in GitHub Desktop.
Powerful Integers
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