Created
April 13, 2021 10:18
-
-
Save vrat28/5de5584788dbd8678d73b858bc417d25 to your computer and use it in GitHub Desktop.
Flatten a nested list with recursion
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
func flattenList(_ nestedList: [NestedInteger]) { | |
for element in nestedList { | |
if element.isInteger() { | |
list.append(element.getInteger()) | |
} | |
else{ | |
flattenList(element.getList()) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment