diff --git a/arrays_strings/compress/compress_solution.ipynb b/arrays_strings/compress/compress_solution.ipynb index 2a89dee..3f14c6e 100644 --- a/arrays_strings/compress/compress_solution.ipynb +++ b/arrays_strings/compress/compress_solution.ipynb @@ -18,7 +18,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "## Problem: Compress a string such that 'AAABCCDDDD' becomes 'A3B1C2D4'. Only compress the string if it saves space.\n", + "## Problem: Compress a string such that 'AAABCCDDDD' becomes 'A3BC2D4'. Only compress the string if it saves space.\n", "\n", "* [Constraints](#Constraints)\n", "* [Test Cases](#Test-Cases)\n", @@ -51,7 +51,7 @@ "* None -> None\n", "* '' -> ''\n", "* 'AABBCC' -> 'AABBCC'\n", - "* 'AAABCCDDDD' -> 'A3B1C2D4'" + "* 'AAABCCDDDD' -> 'A3BC2D4'" ] }, { @@ -105,7 +105,7 @@ " if char == prev_char:\n", " count += 1\n", " else:\n", - " result += prev_char + str(count)\n", + " result += prev_char + (str(count) if count > 1 else '')\n", " prev_char = char\n", " count = 1\n", " result += prev_char + str(count)\n", @@ -145,7 +145,7 @@ " assert_equal(func(None), None)\n", " assert_equal(func(''), '')\n", " assert_equal(func('AABBCC'), 'AABBCC')\n", - " assert_equal(func('AAABCCDDDD'), 'A3B1C2D4')\n", + " assert_equal(func('AAABCCDDDD'), 'A3BC2D4')\n", " print('Success: test_compress')\n", "\n", "\n", diff --git a/arrays_strings/compress/test_compress.py b/arrays_strings/compress/test_compress.py index 7ce5142..4a52b98 100644 --- a/arrays_strings/compress/test_compress.py +++ b/arrays_strings/compress/test_compress.py @@ -7,7 +7,7 @@ class TestCompress(object): assert_equal(func(None), None) assert_equal(func(''), '') assert_equal(func('AABBCC'), 'AABBCC') - assert_equal(func('AAABCCDDDD'), 'A3B1C2D4') + assert_equal(func('AAABCCDDDD'), 'A3BC2D4') print('Success: test_compress')