diff --git a/solutions/sol116.py b/solutions/sol116.py new file mode 100644 index 0000000..d86845a --- /dev/null +++ b/solutions/sol116.py @@ -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 = [] diff --git a/test/116.py b/test/116.py new file mode 100644 index 0000000..5e4aedb --- /dev/null +++ b/test/116.py @@ -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()