forked from llipio/algorithms
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Solution and Test for Issue llipio#116
- Loading branch information
1 parent
8009870
commit a4d21ec
Showing
2 changed files
with
25 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#Himanshu Nachane (@Himanshu1495) | ||
'''input: [1, 2, [2, [5, 3, 4]] ] | ||
output: [1,2, 3, 5, 3, 4] | ||
the output order does not matter, just so long as the array is flattened | ||
''' | ||
|
||
def flatten_array(arr): | ||
for i in arr: | ||
if len(str(i)) == 1: | ||
store.append(i) | ||
else: | ||
flatten_array(i) | ||
return store | ||
store = [] |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import sys | ||
sys.path.insert(0,'../solutions/') | ||
from sol116 import flatten_array | ||
import unittest | ||
|
||
class MyTest(unittest.TestCase): | ||
def test1(self): | ||
self.assertEqual(flatten_array([1,2,[3,4,5],[6,[7,8]],9]),[1,2,3,4,5,6,7,8,9]) | ||
|
||
unittest.main() |