Skip to content

Commit b3b78a8

Browse files
committed
Created using Colaboratory
1 parent 760fa09 commit b3b78a8

File tree

1 file changed

+57
-78
lines changed

1 file changed

+57
-78
lines changed

leetcode_kuro_RnD.ipynb

Lines changed: 57 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -7710,6 +7710,13 @@
77107710
{
77117711
"cell_type": "code",
77127712
"source": [
7713+
"# -*- coding: utf-8 -*-\n",
7714+
"\"\"\"\n",
7715+
"Created on Sat Oct 8 15:02:26 2022\n",
7716+
"\n",
7717+
"@author: souvik.dey\n",
7718+
"\"\"\"\n",
7719+
"\n",
77137720
"# https://leetcode.com/problems/zigzag-conversion/\n",
77147721
"# ---- Work In Progress -----\n",
77157722
"\n",
@@ -7730,118 +7737,90 @@
77307737
" else:\n",
77317738
" direction = 'down'\n",
77327739
" arr=['' for x in range(numRows)]\n",
7733-
" print(arr)\n",
7740+
" # print(arr)\n",
77347741
" count = 0\n",
7735-
" for val in s:\n",
7736-
" print(val)\n",
7742+
" #for val in s:\n",
7743+
" while count < len(s):\n",
7744+
" #print(val)\n",
77377745
" if direction == 'down':\n",
7746+
" # print('-----------down-----------')\n",
77387747
" for i in range(numRows):\n",
7739-
" arr[i] += s[count]\n",
7748+
" if count == len(s): break\n",
7749+
" if arr[i] != '':\n",
7750+
" arr[i] += ' '+s[count]\n",
7751+
" else: \n",
7752+
" arr[i] += s[count]\n",
77407753
" count += 1\n",
7741-
" print(i)\n",
7754+
" # print(i)\n",
77427755
" direction = 'diagonal'\n",
77437756
" numRows -= 1\n",
77447757
" if direction == 'diagonal':\n",
7745-
" print('-----------diagonal-----------')\n",
7746-
" print(numRows)\n",
7747-
" for i in range(numRows):\n",
7758+
" # print('-----------diagonal-----------')\n",
7759+
" # print(numRows)\n",
7760+
" for i in range(numRows_init):\n",
7761+
" if count == len(s): break\n",
77487762
" if i != numRows-1:\n",
77497763
" arr[i] += ' '\n",
77507764
" else:\n",
7751-
" arr[i] += ' '+s[count]\n",
7765+
" arr[i] += s[count]\n",
77527766
" count += 1\n",
7753-
" if numRows >= split_cnt:\n",
7767+
" if numRows > split_cnt:\n",
7768+
" # print('---remains')\n",
77547769
" direction = 'diagonal'\n",
77557770
" numRows -= 1\n",
77567771
" else: \n",
7772+
" # print('---updated')\n",
77577773
" direction = 'down'\n",
77587774
" numRows = numRows_init\n",
77597775
"\n",
7760-
" for i in range(numRows_init):\n",
7761-
" print(arr[i], end = \"\\n\")\n",
7776+
" for i in range(numRows_init):\n",
7777+
" print(arr[i], end = \"\\n\")\n",
77627778
" #print(arr)\n",
77637779
"\n",
77647780
"\n",
77657781
"zigzag_conversion(s, numRows)\n"
77667782
],
77677783
"metadata": {
77687784
"colab": {
7769-
"base_uri": "https://localhost:8080/",
7770-
"height": 1000
7785+
"base_uri": "https://localhost:8080/"
77717786
},
77727787
"id": "aja0oDg5VlHY",
7773-
"outputId": "16aa5095-6725-42c6-b09d-5c46e643b257"
7788+
"outputId": "1c4cd46e-5ec0-457f-d5e2-20d245e639bd"
77747789
},
7775-
"execution_count": 43,
7790+
"execution_count": 56,
77767791
"outputs": [
77777792
{
77787793
"output_type": "stream",
77797794
"name": "stdout",
77807795
"text": [
7781-
"['', '', '', '']\n",
7782-
"P\n",
7783-
"0\n",
7784-
"1\n",
7785-
"2\n",
7786-
"3\n",
7787-
"-----------diagonal-----------\n",
7788-
"3\n",
7789-
"P \n",
7790-
"A \n",
7791-
"Y A\n",
7792-
"P\n",
7793-
"A\n",
7794-
"-----------diagonal-----------\n",
7795-
"2\n",
7796-
"P \n",
7797-
"A L\n",
7798-
"Y A\n",
7799-
"P\n",
7800-
"Y\n",
7801-
"-----------diagonal-----------\n",
7802-
"1\n",
7803-
"P I\n",
7804-
"A L\n",
7805-
"Y A\n",
7806-
"P\n",
7807-
"P\n",
7808-
"0\n",
7809-
"1\n",
7810-
"2\n",
7811-
"3\n",
7812-
"-----------diagonal-----------\n",
7813-
"3\n",
7814-
"P IS \n",
7815-
"A LH \n",
7816-
"Y AI I\n",
7817-
"PR\n",
7818-
"A\n",
7819-
"-----------diagonal-----------\n",
7820-
"2\n",
7821-
"P IS \n",
7822-
"A LH N\n",
7823-
"Y AI I\n",
7824-
"PR\n",
7825-
"L\n",
7826-
"-----------diagonal-----------\n",
7827-
"1\n",
7828-
"P IS G\n",
7829-
"A LH N\n",
7830-
"Y AI I\n",
7831-
"PR\n",
7832-
"I\n"
7796+
"P I N\n",
7797+
"A L S I G\n",
7798+
"YA HR \n",
7799+
"P I \n"
78337800
]
7834-
},
7801+
}
7802+
]
7803+
},
7804+
{
7805+
"cell_type": "code",
7806+
"source": [
7807+
"print([x for x in range(numRows)])\n",
7808+
" "
7809+
],
7810+
"metadata": {
7811+
"id": "x9UttcXT7klc",
7812+
"outputId": "391d3633-0681-4b53-9260-8c0d2c439831",
7813+
"colab": {
7814+
"base_uri": "https://localhost:8080/"
7815+
}
7816+
},
7817+
"execution_count": 50,
7818+
"outputs": [
78357819
{
7836-
"output_type": "error",
7837-
"ename": "IndexError",
7838-
"evalue": "ignored",
7839-
"traceback": [
7840-
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
7841-
"\u001b[0;31mIndexError\u001b[0m Traceback (most recent call last)",
7842-
"\u001b[0;32m<ipython-input-43-33ef3a020acb>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[1;32m 49\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 50\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 51\u001b[0;31m \u001b[0mzigzag_conversion\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0ms\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mnumRows\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
7843-
"\u001b[0;32m<ipython-input-43-33ef3a020acb>\u001b[0m in \u001b[0;36mzigzag_conversion\u001b[0;34m(s, numRows)\u001b[0m\n\u001b[1;32m 23\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mdirection\u001b[0m \u001b[0;34m==\u001b[0m \u001b[0;34m'down'\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 24\u001b[0m \u001b[0;32mfor\u001b[0m \u001b[0mi\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mrange\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mnumRows\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 25\u001b[0;31m \u001b[0marr\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mi\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;34m+=\u001b[0m \u001b[0ms\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mcount\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 26\u001b[0m \u001b[0mcount\u001b[0m \u001b[0;34m+=\u001b[0m \u001b[0;36m1\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 27\u001b[0m \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mi\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
7844-
"\u001b[0;31mIndexError\u001b[0m: list index out of range"
7820+
"output_type": "stream",
7821+
"name": "stdout",
7822+
"text": [
7823+
"[0, 1, 2, 3]\n"
78457824
]
78467825
}
78477826
]

0 commit comments

Comments
 (0)