From 6ad114c3aeb4e39ca47e614c59c90c5a15f63af5 Mon Sep 17 00:00:00 2001 From: qq_44193969 <2608882093@qq.com> Date: Thu, 20 Jan 2022 16:47:02 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E4=B9=A0=E9=A2=98=E6=95=B0?= =?UTF-8?q?=E9=87=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../3.python/101.exercises/config.json" | 2 +- .../3.python/101.exercises/solution.json" | 7 + .../3.python/101.exercises/solution.md" | 82 ++++++++++ .../3.python/104.exercises/config.json" | 2 +- .../3.python/104.exercises/solution.json" | 7 + .../3.python/104.exercises/solution.md" | 63 ++++++++ .../3.python/108.exercises/config.json" | 2 +- .../3.python/108.exercises/solution.json" | 7 + .../3.python/108.exercises/solution.md" | 89 +++++++++++ .../3.python/110.exercises/config.json" | 2 +- .../3.python/110.exercises/solution.json" | 2 +- .../3.python/110.exercises/solution.md" | 99 ++++++++++++ .../3.python/111.exercises/config.json" | 10 ++ .../3.python/111.exercises/solution.json" | 7 + .../3.python/111.exercises/solution.md" | 92 +++++++++++ .../3.python/112.exercises/config.json" | 10 ++ .../3.python/112.exercises/solution.json" | 7 + .../3.python/112.exercises/solution.md" | 89 +++++++++++ .../3.python/118.exercises/config.json" | 10 ++ .../3.python/118.exercises/solution.json" | 2 +- .../3.python/118.exercises/solution.md" | 80 ++++++++++ .../3.python/119.exercises/config.json" | 10 ++ .../3.python/119.exercises/solution.json" | 7 + .../3.python/119.exercises/solution.md" | 92 +++++++++++ .../3.python/121.exercises/config.json" | 10 ++ .../3.python/121.exercises/solution.json" | 7 + .../3.python/121.exercises/solution.md" | 83 ++++++++++ .../3.python/122.exercises/config.json" | 10 ++ .../3.python/122.exercises/solution.json" | 7 + .../3.python/122.exercises/solution.md" | 118 ++++++++++++++ .../3.python/125.exercises/config.json" | 10 ++ .../3.python/125.exercises/solution.json" | 2 +- .../3.python/125.exercises/solution.md" | 85 ++++++++++ .../3.python/136.exercises/config.json" | 10 ++ .../3.python/136.exercises/solution.json" | 7 + .../3.python/136.exercises/solution.md" | 61 ++++++++ .../3.python/141.exercises/config.json" | 10 ++ .../3.python/141.exercises/solution.json" | 7 + .../3.python/141.exercises/solution.md" | 103 ++++++++++++ .../3.python/144.exercises/config.json" | 10 ++ .../3.python/144.exercises/solution.json" | 7 + .../3.python/144.exercises/solution.md" | 104 ++++++++++++ .../3.python/145.exercises/config.json" | 10 ++ .../3.python/145.exercises/solution.json" | 7 + .../3.python/145.exercises/solution.md" | 72 +++++++++ .../3.python/155.exercises/config.json" | 10 ++ .../3.python/155.exercises/solution.json" | 7 + .../3.python/155.exercises/solution.md" | 97 ++++++++++++ .../3.python/160.exercises/config.json" | 10 ++ .../3.python/160.exercises/solution.json" | 7 + .../3.python/160.exercises/solution.md" | 138 ++++++++++++++++ .../3.python/167.exercises/config.json" | 10 ++ .../3.python/167.exercises/solution.json" | 7 + .../3.python/167.exercises/solution.md" | 92 +++++++++++ .../3.python/168.exercises/config.json" | 10 ++ .../3.python/168.exercises/solution.json" | 7 + .../3.python/168.exercises/solution.md" | 111 +++++++++++++ .../3.python/169.exercises/config.json" | 10 ++ .../3.python/169.exercises/solution.json" | 7 + .../3.python/169.exercises/solution.md" | 75 +++++++++ .../3.python/171.exercises/config.json" | 10 ++ .../3.python/171.exercises/solution.json" | 7 + .../3.python/171.exercises/solution.md" | 98 ++++++++++++ .../3.python/172.exercises/config.json" | 10 ++ .../3.python/172.exercises/solution.json" | 4 +- .../3.python/172.exercises/solution.md" | 83 ++++++++++ .../3.python/190.exercises/config.json" | 10 ++ .../3.python/190.exercises/solution.json" | 7 + .../3.python/190.exercises/solution.md" | 82 ++++++++++ .../3.python/191.exercises/config.json" | 10 ++ .../3.python/191.exercises/solution.json" | 2 +- .../3.python/191.exercises/solution.md" | 107 +++++++++++++ .../3.python/202.exercises/config.json" | 10 ++ .../3.python/202.exercises/solution.json" | 7 + .../3.python/202.exercises/solution.md" | 95 +++++++++++ .../3.python/203.exercises/config.json" | 10 ++ .../3.python/203.exercises/solution.json" | 7 + .../3.python/203.exercises/solution.md" | 93 +++++++++++ .../3.python/204.exercises/config.json" | 10 ++ .../3.python/204.exercises/solution.json" | 7 + .../3.python/204.exercises/solution.md" | 80 ++++++++++ .../3.python/205.exercises/config.json" | 10 ++ .../3.python/205.exercises/solution.json" | 7 + .../3.python/205.exercises/solution.md" | 94 +++++++++++ .../3.python/206.exercises/config.json" | 10 ++ .../3.python/206.exercises/solution.json" | 7 + .../3.python/206.exercises/solution.md" | 104 ++++++++++++ .../3.python/217.exercises/config.json" | 10 ++ .../3.python/217.exercises/solution.json" | 7 + .../3.python/217.exercises/solution.md" | 68 ++++++++ .../3.python/219.exercises/config.json" | 10 ++ .../3.python/219.exercises/solution.json" | 7 + .../3.python/219.exercises/solution.md" | 78 +++++++++ .../3.python/225.exercises/config.json" | 10 ++ .../3.python/225.exercises/solution.json" | 7 + .../3.python/225.exercises/solution.md" | 133 ++++++++++++++++ .../3.python/226.exercises/config.json" | 10 ++ .../3.python/226.exercises/solution.json" | 7 + .../3.python/226.exercises/solution.md" | 80 ++++++++++ .../3.python/228.exercises/config.json" | 10 ++ .../3.python/228.exercises/solution.json" | 2 +- .../3.python/228.exercises/solution.md" | 126 +++++++++++++++ .../3.python/231.exercises/config.json" | 10 ++ .../3.python/231.exercises/solution.json" | 7 + .../3.python/231.exercises/solution.md" | 98 ++++++++++++ .../3.python/232.exercises/config.json" | 10 ++ .../3.python/232.exercises/solution.json" | 7 + .../3.python/232.exercises/solution.md" | 148 ++++++++++++++++++ .../3.python/234.exercises/config.json" | 10 ++ .../3.python/234.exercises/solution.json" | 7 + .../3.python/234.exercises/solution.md" | 92 +++++++++++ .../3.python/102.exercises/config.json" | 10 ++ .../3.python/102.exercises/solution.json" | 7 + .../3.python/102.exercises/solution.md" | 87 ++++++++++ .../3.python/103.exercises/config.json" | 10 ++ .../3.python/103.exercises/solution.json" | 7 + .../3.python/103.exercises/solution.md" | 91 +++++++++++ .../3.python/105.exercises/config.json" | 10 ++ .../3.python/105.exercises/solution.json" | 7 + .../3.python/105.exercises/solution.md" | 80 ++++++++++ .../3.python/106.exercises/config.json" | 10 ++ .../3.python/106.exercises/solution.json" | 7 + .../3.python/106.exercises/solution.md" | 87 ++++++++++ .../3.python/107.exercises/config.json" | 10 ++ .../3.python/107.exercises/solution.json" | 7 + .../3.python/107.exercises/solution.md" | 75 +++++++++ .../3.python/109.exercises/config.json" | 10 ++ .../3.python/109.exercises/solution.json" | 7 + .../3.python/109.exercises/solution.md" | 89 +++++++++++ .../3.python/113.exercises/config.json" | 10 ++ .../3.python/113.exercises/solution.json" | 7 + .../3.python/113.exercises/solution.md" | 96 ++++++++++++ .../3.python/114.exercises/config.json" | 10 ++ .../3.python/114.exercises/solution.json" | 7 + .../3.python/114.exercises/solution.md" | 101 ++++++++++++ .../3.python/116.exercises/config.json" | 10 ++ .../3.python/116.exercises/solution.json" | 7 + .../3.python/116.exercises/solution.md" | 106 +++++++++++++ .../3.python/117.exercises/config.json" | 10 ++ .../3.python/117.exercises/solution.json" | 7 + .../3.python/117.exercises/solution.md" | 118 ++++++++++++++ .../3.python/120.exercises/config.json" | 10 ++ .../3.python/120.exercises/solution.json" | 7 + .../3.python/120.exercises/solution.md" | 93 +++++++++++ .../3.python/128.exercises/config.json" | 10 ++ .../3.python/128.exercises/solution.json" | 7 + .../3.python/128.exercises/solution.md" | 87 ++++++++++ .../3.python/129.exercises/config.json" | 10 ++ .../3.python/129.exercises/solution.json" | 7 + .../3.python/129.exercises/solution.md" | 101 ++++++++++++ .../3.python/130.exercises/config.json" | 10 ++ .../3.python/130.exercises/solution.json" | 7 + .../3.python/130.exercises/solution.md" | 112 +++++++++++++ .../3.python/131.exercises/config.json" | 10 ++ .../3.python/131.exercises/solution.json" | 7 + .../3.python/131.exercises/solution.md" | 83 ++++++++++ .../3.python/133.exercises/config.json" | 10 ++ .../3.python/133.exercises/solution.json" | 7 + .../3.python/133.exercises/solution.md" | 131 ++++++++++++++++ .../3.python/134.exercises/config.json" | 10 ++ .../3.python/134.exercises/solution.json" | 7 + .../3.python/134.exercises/solution.md" | 101 ++++++++++++ .../3.python/137.exercises/config.json" | 10 ++ .../3.python/137.exercises/solution.json" | 7 + .../3.python/137.exercises/solution.md" | 79 ++++++++++ .../3.python/138.exercises/config.json" | 10 ++ .../3.python/138.exercises/solution.json" | 7 + .../3.python/138.exercises/solution.md" | 127 +++++++++++++++ .../3.python/139.exercises/config.json" | 10 ++ .../3.python/139.exercises/solution.json" | 7 + .../3.python/139.exercises/solution.md" | 83 ++++++++++ .../3.python/142.exercises/config.json" | 10 ++ .../3.python/142.exercises/solution.json" | 7 + .../3.python/142.exercises/solution.md" | 105 +++++++++++++ .../3.python/143.exercises/config.json" | 10 ++ .../3.python/143.exercises/solution.json" | 7 + .../3.python/143.exercises/solution.md" | 105 +++++++++++++ .../3.python/146.exercises/config.json" | 10 ++ .../3.python/146.exercises/solution.json" | 7 + .../3.python/146.exercises/solution.md" | 131 ++++++++++++++++ .../3.python/147.exercises/config.json" | 10 ++ .../3.python/147.exercises/solution.json" | 7 + .../3.python/147.exercises/solution.md" | 108 +++++++++++++ .../3.python/148.exercises/config.json" | 10 ++ .../3.python/148.exercises/solution.json" | 7 + .../3.python/148.exercises/solution.md" | 121 ++++++++++++++ .../3.python/150.exercises/config.json" | 10 ++ .../3.python/150.exercises/solution.json" | 7 + .../3.python/150.exercises/solution.md" | 137 ++++++++++++++++ .../3.python/151.exercises/config.json" | 10 ++ .../3.python/151.exercises/solution.json" | 2 +- .../3.python/151.exercises/solution.md" | 119 ++++++++++++++ .../3.python/152.exercises/config.json" | 10 ++ .../3.python/152.exercises/solution.json" | 7 + .../3.python/152.exercises/solution.md" | 77 +++++++++ .../3.python/153.exercises/config.json" | 10 ++ .../3.python/153.exercises/solution.json" | 7 + .../3.python/153.exercises/solution.md" | 101 ++++++++++++ .../3.python/162.exercises/config.json" | 10 ++ .../3.python/162.exercises/solution.json" | 7 + .../3.python/162.exercises/solution.md" | 83 ++++++++++ .../3.python/165.exercises/config.json" | 10 ++ .../3.python/165.exercises/solution.json" | 7 + .../3.python/165.exercises/solution.md" | 140 +++++++++++++++++ .../3.python/166.exercises/config.json" | 10 ++ .../3.python/166.exercises/solution.json" | 7 + .../3.python/166.exercises/solution.md" | 128 +++++++++++++++ .../3.python/173.exercises/config.json" | 10 ++ .../3.python/173.exercises/solution.json" | 7 + .../3.python/173.exercises/solution.md" | 128 +++++++++++++++ .../3.python/179.exercises/config.json" | 10 ++ .../3.python/179.exercises/solution.json" | 7 + .../3.python/179.exercises/solution.md" | 93 +++++++++++ .../3.python/187.exercises/config.json" | 10 ++ .../3.python/187.exercises/solution.json" | 7 + .../3.python/187.exercises/solution.md" | 77 +++++++++ .../3.python/189.exercises/config.json" | 10 ++ .../3.python/189.exercises/solution.json" | 7 + .../3.python/189.exercises/solution.md" | 93 +++++++++++ .../3.python/198.exercises/config.json" | 10 ++ .../3.python/198.exercises/solution.json" | 7 + .../3.python/198.exercises/solution.md" | 77 +++++++++ .../3.python/199.exercises/config.json" | 10 ++ .../3.python/199.exercises/solution.json" | 7 + .../3.python/199.exercises/solution.md" | 96 ++++++++++++ .../3.python/200.exercises/config.json" | 10 ++ .../3.python/200.exercises/solution.json" | 7 + .../3.python/200.exercises/solution.md" | 101 ++++++++++++ .../3.python/115.exercises/config.json" | 10 ++ .../3.python/115.exercises/solution.json" | 7 + .../3.python/115.exercises/solution.md" | 91 +++++++++++ .../3.python/123.exercises/config.json" | 10 ++ .../3.python/123.exercises/solution.json" | 7 + .../3.python/123.exercises/solution.md" | 99 ++++++++++++ .../3.python/124.exercises/config.json" | 10 ++ .../3.python/124.exercises/solution.json" | 7 + .../3.python/124.exercises/solution.md" | 86 ++++++++++ .../3.python/126.exercises/config.json" | 10 ++ .../3.python/126.exercises/solution.json" | 7 + .../3.python/126.exercises/solution.md" | 112 +++++++++++++ .../3.python/127.exercises/config.json" | 10 ++ .../3.python/127.exercises/solution.json" | 7 + .../3.python/127.exercises/solution.md" | 115 ++++++++++++++ .../3.python/132.exercises/config.json" | 10 ++ .../3.python/132.exercises/solution.json" | 7 + .../3.python/132.exercises/solution.md" | 93 +++++++++++ .../3.python/135.exercises/config.json" | 10 ++ .../3.python/135.exercises/solution.json" | 7 + .../3.python/135.exercises/solution.md" | 83 ++++++++++ .../3.python/140.exercises/config.json" | 10 ++ .../3.python/140.exercises/solution.json" | 7 + .../3.python/140.exercises/solution.md" | 109 +++++++++++++ .../3.python/149.exercises/config.json" | 10 ++ .../3.python/149.exercises/solution.json" | 7 + .../3.python/149.exercises/solution.md" | 91 +++++++++++ .../3.python/154.exercises/config.json" | 10 ++ .../3.python/154.exercises/solution.json" | 7 + .../3.python/154.exercises/solution.md" | 93 +++++++++++ .../3.python/164.exercises/config.json" | 10 ++ .../3.python/164.exercises/solution.json" | 7 + .../3.python/164.exercises/solution.md" | 87 ++++++++++ .../3.python/174.exercises/config.json" | 10 ++ .../3.python/174.exercises/solution.json" | 7 + .../3.python/174.exercises/solution.md" | 106 +++++++++++++ .../3.python/188.exercises/config.json" | 10 ++ .../3.python/188.exercises/solution.json" | 7 + .../3.python/188.exercises/solution.md" | 89 +++++++++++ .../3.python/212.exercises/config.json" | 10 ++ .../3.python/212.exercises/solution.json" | 7 + .../3.python/212.exercises/solution.md" | 107 +++++++++++++ .../3.python/214.exercises/config.json" | 10 ++ .../3.python/214.exercises/solution.json" | 7 + .../3.python/214.exercises/solution.md" | 71 +++++++++ .../3.python/218.exercises/config.json" | 10 ++ .../3.python/218.exercises/solution.json" | 7 + .../3.python/218.exercises/solution.md" | 130 +++++++++++++++ .../3.python/224.exercises/config.json" | 10 ++ .../3.python/224.exercises/solution.json" | 7 + .../3.python/224.exercises/solution.md" | 96 ++++++++++++ .../3.python/233.exercises/config.json" | 10 ++ .../3.python/233.exercises/solution.json" | 7 + .../3.python/233.exercises/solution.md" | 69 ++++++++ .../3.python/239.exercises/config.json" | 10 ++ .../3.python/239.exercises/solution.json" | 7 + .../3.python/239.exercises/solution.md" | 111 +++++++++++++ .../3.python/273.exercises/config.json" | 10 ++ .../3.python/273.exercises/solution.json" | 7 + .../3.python/273.exercises/solution.md" | 123 +++++++++++++++ .../3.python/282.exercises/config.json" | 10 ++ .../3.python/282.exercises/solution.json" | 7 + .../3.python/282.exercises/solution.md" | 127 +++++++++++++++ .../3.python/295.exercises/config.json" | 10 ++ .../3.python/295.exercises/solution.json" | 7 + .../3.python/295.exercises/solution.md" | 94 +++++++++++ .../3.python/297.exercises/config.json" | 10 ++ .../3.python/297.exercises/solution.json" | 7 + .../3.python/297.exercises/solution.md" | 124 +++++++++++++++ .../3.python/301.exercises/config.json" | 10 ++ .../3.python/301.exercises/solution.json" | 7 + .../3.python/301.exercises/solution.md" | 129 +++++++++++++++ .../3.python/312.exercises/config.json" | 10 ++ .../3.python/312.exercises/solution.json" | 7 + .../3.python/312.exercises/solution.md" | 78 +++++++++ .../3.python/315.exercises/config.json" | 10 ++ .../3.python/315.exercises/solution.json" | 7 + .../3.python/315.exercises/solution.md" | 123 +++++++++++++++ .../3.python/321.exercises/config.json" | 10 ++ .../3.python/321.exercises/solution.json" | 7 + .../3.python/321.exercises/solution.md" | 92 +++++++++++ .../3.python/327.exercises/config.json" | 10 ++ .../3.python/327.exercises/solution.json" | 7 + .../3.python/327.exercises/solution.md" | 118 ++++++++++++++ .../3.python/329.exercises/config.json" | 10 ++ .../3.python/329.exercises/solution.json" | 4 +- .../3.python/329.exercises/solution.md" | 106 +++++++++++++ .../3.python/330.exercises/config.json" | 10 ++ .../3.python/330.exercises/solution.json" | 7 + .../3.python/330.exercises/solution.md" | 74 +++++++++ .../3.python/335.exercises/config.json" | 10 ++ .../3.python/335.exercises/solution.json" | 7 + .../3.python/335.exercises/solution.md" | 83 ++++++++++ .../3.python/336.exercises/config.json" | 10 ++ .../3.python/336.exercises/solution.json" | 7 + .../3.python/336.exercises/solution.md" | 116 ++++++++++++++ .../3.python/352.exercises/config.json" | 10 ++ .../3.python/352.exercises/solution.json" | 7 + .../3.python/352.exercises/solution.md" | 143 +++++++++++++++++ .../3.python/354.exercises/config.json" | 10 ++ .../3.python/354.exercises/solution.json" | 7 + .../3.python/354.exercises/solution.md" | 85 ++++++++++ .../3.python/363.exercises/config.json" | 10 ++ .../3.python/363.exercises/solution.json" | 7 + .../3.python/363.exercises/solution.md" | 97 ++++++++++++ .../3.python/381.exercises/config.json" | 10 ++ .../3.python/381.exercises/solution.json" | 7 + .../3.python/381.exercises/solution.md" | 106 +++++++++++++ .../python/102.exercises/solution.md" | 29 +++- .../python/103.exercises/solution.md" | 37 ++++- .../python/105.exercises/solution.md" | 17 +- .../python/106.exercises/solution.md" | 33 ++++ .../python/107.exercises/solution.md" | 19 ++- .../python/109.exercises/solution.md" | 39 ++++- .../python/113.exercises/solution.md" | 20 +++ .../python/114.exercises/solution.md" | 23 +++ .../python/116.exercises/solution.md" | 29 +++- .../python/117.exercises/solution.md" | 35 +++++ .../python/120.exercises/solution.md" | 13 ++ .../python/128.exercises/solution.md" | 23 +++ .../python/129.exercises/solution.md" | 21 ++- .../python/130.exercises/solution.md" | 44 ++++++ .../python/131.exercises/solution.md" | 19 +++ .../python/133.exercises/solution.md" | 26 +++ .../python/134.exercises/solution.md" | 19 +++ .../python/137.exercises/solution.md" | 12 ++ .../python/138.exercises/solution.md" | 28 ++++ .../python/139.exercises/solution.md" | 18 +++ .../python/142.exercises/solution.md" | 18 ++- .../python/143.exercises/solution.md" | 34 ++++ .../python/146.exercises/solution.md" | 43 +++++ .../python/147.exercises/solution.md" | 43 +++++ .../python/148.exercises/solution.md" | 48 +++++- .../python/150.exercises/solution.md" | 29 ++++ .../python/151.exercises/solution.md" | 10 ++ .../python/152.exercises/solution.md" | 25 +++ .../python/153.exercises/solution.md" | 18 +++ .../python/156.exercises/solution.md" | 36 ----- .../python/159.exercises/solution.json" | 7 - .../python/159.exercises/solution.md" | 36 ----- .../python/161.exercises/solution.md" | 36 ----- .../python/162.exercises/solution.md" | 12 ++ .../python/165.exercises/solution.md" | 44 +++++- .../python/166.exercises/solution.md" | 39 +++++ .../python/173.exercises/solution.md" | 38 ++++- .../python/177.exercises/solution.json" | 7 - .../python/177.exercises/solution.md" | 55 ------- .../python/178.exercises/config.json" | 10 -- .../python/178.exercises/solution.json" | 7 - .../python/178.exercises/solution.md" | 67 -------- .../python/179.exercises/solution.md" | 16 ++ .../python/180.exercises/config.json" | 10 -- .../python/180.exercises/solution.json" | 7 - .../python/180.exercises/solution.md" | 81 ---------- .../python/184.exercises/config.json" | 10 -- .../python/184.exercises/solution.json" | 7 - .../python/184.exercises/solution.md" | 70 --------- .../python/186.exercises/config.json" | 10 -- .../python/186.exercises/solution.md" | 36 ----- .../python/187.exercises/solution.md" | 13 ++ .../python/189.exercises/solution.md" | 12 ++ .../python/192.exercises/config.json" | 10 -- .../python/192.exercises/solution.md" | 68 -------- .../python/194.exercises/config.json" | 10 -- .../python/194.exercises/solution.md" | 58 ------- .../python/198.exercises/solution.md" | 10 ++ .../python/199.exercises/solution.md" | 27 +++- .../python/200.exercises/solution.md" | 23 +++ .../python/115.exercises/solution.md" | 16 +- .../python/123.exercises/solution.md" | 17 +- .../python/124.exercises/solution.md" | 19 +++ .../python/126.exercises/solution.md" | 31 +++- .../python/127.exercises/solution.md" | 41 ++++- .../python/132.exercises/solution.md" | 19 ++- .../python/135.exercises/solution.md" | 21 ++- .../python/140.exercises/solution.md" | 30 ++++ .../python/149.exercises/solution.md" | 29 +++- .../python/154.exercises/solution.md" | 14 +- .../python/158.exercises/config.json" | 10 -- .../python/158.exercises/solution.json" | 7 - .../python/158.exercises/solution.md" | 36 ----- .../python/164.exercises/solution.md" | 31 +++- .../python/174.exercises/solution.md" | 14 ++ .../python/185.exercises/config.json" | 10 -- .../python/185.exercises/solution.json" | 7 - .../python/185.exercises/solution.md" | 75 --------- .../python/188.exercises/solution.md" | 23 ++- .../python/212.exercises/solution.md" | 39 ++++- .../python/214.exercises/solution.md" | 11 +- .../python/218.exercises/solution.md" | 52 ++++++ .../python/224.exercises/solution.md" | 28 +++- .../python/233.exercises/solution.md" | 10 +- .../python/239.exercises/solution.md" | 19 ++- .../python/248.exercises/config.json" | 10 -- .../python/248.exercises/solution.json" | 7 - .../python/248.exercises/solution.md" | 36 ----- .../python/262.exercises/config.json" | 10 -- .../python/262.exercises/solution.json" | 7 - .../python/262.exercises/solution.md" | 146 ----------------- .../python/265.exercises/config.json" | 10 -- .../python/265.exercises/solution.md" | 36 ----- .../python/269.exercises/config.json" | 10 -- .../python/269.exercises/solution.md" | 36 ----- .../python/272.exercises/config.json" | 10 -- .../python/272.exercises/solution.json" | 7 - .../python/272.exercises/solution.md" | 36 ----- .../python/273.exercises/solution.md" | 50 +++++- .../python/282.exercises/solution.md" | 46 ++++++ .../python/295.exercises/solution.md" | 29 ++++ .../python/296.exercises/config.json" | 10 -- .../python/296.exercises/solution.json" | 7 - .../python/296.exercises/solution.md" | 36 ----- .../python/297.exercises/solution.md" | 46 +++++- .../python/301.exercises/solution.md" | 57 +++++++ .../python/302.exercises/config.json" | 10 -- .../python/302.exercises/solution.json" | 7 - .../python/302.exercises/solution.md" | 36 ----- .../python/305.exercises/config.json" | 10 -- .../python/305.exercises/solution.json" | 7 - .../python/305.exercises/solution.md" | 36 ----- .../python/308.exercises/config.json" | 10 -- .../python/308.exercises/solution.json" | 7 - .../python/308.exercises/solution.md" | 36 ----- .../python/312.exercises/solution.md" | 12 +- .../python/315.exercises/solution.md" | 49 ++++++ .../python/317.exercises/config.json" | 10 -- .../python/317.exercises/solution.json" | 7 - .../python/317.exercises/solution.md" | 36 ----- .../python/321.exercises/solution.md" | 26 ++- .../python/327.exercises/solution.md" | 52 ++++++ .../python/329.exercises/solution.md" | 32 ++++ .../python/330.exercises/solution.md" | 14 ++ .../python/335.exercises/solution.md" | 13 +- .../python/336.exercises/solution.md" | 46 ++++++ .../python/352.exercises/solution.md" | 56 +++++++ .../python/354.exercises/solution.md" | 17 ++ .../python/358.exercises/config.json" | 10 -- .../python/358.exercises/solution.json" | 7 - .../python/358.exercises/solution.md" | 36 ----- .../python/363.exercises/solution.md" | 29 +++- .../python/381.exercises/solution.md" | 37 +++++ .../python/101.exercises/solution.md" | 21 ++- .../python/104.exercises/solution.md" | 13 +- .../python/108.exercises/solution.md" | 21 +++ .../python/110.exercises/solution.md" | 26 ++- .../python/111.exercises/solution.md" | 28 +++- .../python/112.exercises/solution.md" | 21 ++- .../python/118.exercises/solution.md" | 17 +- .../python/119.exercises/solution.md" | 16 +- .../python/121.exercises/solution.md" | 16 +- .../python/122.exercises/solution.md" | 41 +++++ .../python/125.exercises/solution.md" | 23 ++- .../python/136.exercises/solution.md" | 11 +- .../python/141.exercises/solution.md" | 19 ++- .../python/144.exercises/solution.md" | 19 ++- .../python/145.exercises/solution.md" | 26 ++- .../python/155.exercises/solution.md" | 23 +++ .../python/157.exercises/config.json" | 10 -- .../python/157.exercises/solution.json" | 7 - .../python/157.exercises/solution.md" | 36 ----- .../python/160.exercises/solution.md" | 38 ++++- .../python/163.exercises/config.json" | 10 -- .../python/163.exercises/solution.md" | 36 ----- .../python/167.exercises/solution.md" | 18 ++- .../python/168.exercises/solution.md" | 25 ++- .../python/169.exercises/solution.md" | 13 ++ .../python/170.exercises/config.json" | 10 -- .../python/170.exercises/solution.json" | 7 - .../python/170.exercises/solution.md" | 36 ----- .../python/171.exercises/solution.md" | 7 + .../python/172.exercises/solution.md" | 9 +- .../python/175.exercises/config.json" | 10 -- .../python/175.exercises/solution.json" | 7 - .../python/175.exercises/solution.md" | 69 -------- .../python/176.exercises/config.json" | 10 -- .../python/176.exercises/solution.json" | 7 - .../python/176.exercises/solution.md" | 55 ------- .../python/181.exercises/config.json" | 10 -- .../python/181.exercises/solution.json" | 7 - .../python/181.exercises/solution.md" | 56 ------- .../python/182.exercises/config.json" | 10 -- .../python/182.exercises/solution.json" | 7 - .../python/182.exercises/solution.md" | 59 ------- .../python/183.exercises/config.json" | 10 -- .../python/183.exercises/solution.json" | 7 - .../python/183.exercises/solution.md" | 69 -------- .../python/190.exercises/solution.md" | 10 +- .../python/191.exercises/solution.md" | 19 ++- .../python/193.exercises/config.json" | 10 -- .../python/193.exercises/solution.json" | 7 - .../python/193.exercises/solution.md" | 60 ------- .../python/195.exercises/config.json" | 10 -- .../python/195.exercises/solution.json" | 7 - .../python/195.exercises/solution.md" | 62 -------- .../python/196.exercises/config.json" | 10 -- .../python/196.exercises/solution.json" | 7 - .../python/196.exercises/solution.md" | 66 -------- .../python/197.exercises/config.json" | 10 -- .../python/197.exercises/solution.json" | 7 - .../python/197.exercises/solution.md" | 82 ---------- .../python/202.exercises/solution.md" | 21 ++- .../python/203.exercises/solution.md" | 26 ++- .../python/204.exercises/solution.md" | 14 ++ .../python/205.exercises/solution.md" | 24 +++ .../python/206.exercises/solution.md" | 28 ++++ .../python/217.exercises/solution.md" | 11 +- .../python/219.exercises/solution.md" | 26 ++- .../python/225.exercises/solution.md" | 46 +++++- .../python/226.exercises/solution.md" | 20 +++ .../python/228.exercises/solution.md" | 23 +++ .../python/231.exercises/solution.md" | 10 +- .../python/232.exercises/solution.md" | 52 ++++++ .../python/234.exercises/solution.md" | 26 +++ 541 files changed, 15730 insertions(+), 2426 deletions(-) rename "data_source/exercises/\344\270\255\347\255\211/python/156.exercises/config.json" => "data/1.dailycode\345\210\235\351\230\266/3.python/101.exercises/config.json" (67%) create mode 100644 "data/1.dailycode\345\210\235\351\230\266/3.python/101.exercises/solution.json" create mode 100644 "data/1.dailycode\345\210\235\351\230\266/3.python/101.exercises/solution.md" rename "data_source/exercises/\344\270\255\347\255\211/python/161.exercises/config.json" => "data/1.dailycode\345\210\235\351\230\266/3.python/104.exercises/config.json" (67%) create mode 100644 "data/1.dailycode\345\210\235\351\230\266/3.python/104.exercises/solution.json" create mode 100644 "data/1.dailycode\345\210\235\351\230\266/3.python/104.exercises/solution.md" rename "data_source/exercises/\344\270\255\347\255\211/python/177.exercises/config.json" => "data/1.dailycode\345\210\235\351\230\266/3.python/108.exercises/config.json" (67%) create mode 100644 "data/1.dailycode\345\210\235\351\230\266/3.python/108.exercises/solution.json" create mode 100644 "data/1.dailycode\345\210\235\351\230\266/3.python/108.exercises/solution.md" rename "data_source/exercises/\344\270\255\347\255\211/python/159.exercises/config.json" => "data/1.dailycode\345\210\235\351\230\266/3.python/110.exercises/config.json" (67%) rename "data_source/exercises/\344\270\255\347\255\211/python/156.exercises/solution.json" => "data/1.dailycode\345\210\235\351\230\266/3.python/110.exercises/solution.json" (70%) create mode 100644 "data/1.dailycode\345\210\235\351\230\266/3.python/110.exercises/solution.md" create mode 100644 "data/1.dailycode\345\210\235\351\230\266/3.python/111.exercises/config.json" create mode 100644 "data/1.dailycode\345\210\235\351\230\266/3.python/111.exercises/solution.json" create mode 100644 "data/1.dailycode\345\210\235\351\230\266/3.python/111.exercises/solution.md" create mode 100644 "data/1.dailycode\345\210\235\351\230\266/3.python/112.exercises/config.json" create mode 100644 "data/1.dailycode\345\210\235\351\230\266/3.python/112.exercises/solution.json" create mode 100644 "data/1.dailycode\345\210\235\351\230\266/3.python/112.exercises/solution.md" create mode 100644 "data/1.dailycode\345\210\235\351\230\266/3.python/118.exercises/config.json" rename "data_source/exercises/\345\233\260\351\232\276/python/265.exercises/solution.json" => "data/1.dailycode\345\210\235\351\230\266/3.python/118.exercises/solution.json" (68%) create mode 100644 "data/1.dailycode\345\210\235\351\230\266/3.python/118.exercises/solution.md" create mode 100644 "data/1.dailycode\345\210\235\351\230\266/3.python/119.exercises/config.json" create mode 100644 "data/1.dailycode\345\210\235\351\230\266/3.python/119.exercises/solution.json" create mode 100644 "data/1.dailycode\345\210\235\351\230\266/3.python/119.exercises/solution.md" create mode 100644 "data/1.dailycode\345\210\235\351\230\266/3.python/121.exercises/config.json" create mode 100644 "data/1.dailycode\345\210\235\351\230\266/3.python/121.exercises/solution.json" create mode 100644 "data/1.dailycode\345\210\235\351\230\266/3.python/121.exercises/solution.md" create mode 100644 "data/1.dailycode\345\210\235\351\230\266/3.python/122.exercises/config.json" create mode 100644 "data/1.dailycode\345\210\235\351\230\266/3.python/122.exercises/solution.json" create mode 100644 "data/1.dailycode\345\210\235\351\230\266/3.python/122.exercises/solution.md" create mode 100644 "data/1.dailycode\345\210\235\351\230\266/3.python/125.exercises/config.json" rename "data_source/exercises/\344\270\255\347\255\211/python/161.exercises/solution.json" => "data/1.dailycode\345\210\235\351\230\266/3.python/125.exercises/solution.json" (68%) create mode 100644 "data/1.dailycode\345\210\235\351\230\266/3.python/125.exercises/solution.md" create mode 100644 "data/1.dailycode\345\210\235\351\230\266/3.python/136.exercises/config.json" create mode 100644 "data/1.dailycode\345\210\235\351\230\266/3.python/136.exercises/solution.json" create mode 100644 "data/1.dailycode\345\210\235\351\230\266/3.python/136.exercises/solution.md" create mode 100644 "data/1.dailycode\345\210\235\351\230\266/3.python/141.exercises/config.json" create mode 100644 "data/1.dailycode\345\210\235\351\230\266/3.python/141.exercises/solution.json" create mode 100644 "data/1.dailycode\345\210\235\351\230\266/3.python/141.exercises/solution.md" create mode 100644 "data/1.dailycode\345\210\235\351\230\266/3.python/144.exercises/config.json" create mode 100644 "data/1.dailycode\345\210\235\351\230\266/3.python/144.exercises/solution.json" create mode 100644 "data/1.dailycode\345\210\235\351\230\266/3.python/144.exercises/solution.md" create mode 100644 "data/1.dailycode\345\210\235\351\230\266/3.python/145.exercises/config.json" create mode 100644 "data/1.dailycode\345\210\235\351\230\266/3.python/145.exercises/solution.json" create mode 100644 "data/1.dailycode\345\210\235\351\230\266/3.python/145.exercises/solution.md" create mode 100644 "data/1.dailycode\345\210\235\351\230\266/3.python/155.exercises/config.json" create mode 100644 "data/1.dailycode\345\210\235\351\230\266/3.python/155.exercises/solution.json" create mode 100644 "data/1.dailycode\345\210\235\351\230\266/3.python/155.exercises/solution.md" create mode 100644 "data/1.dailycode\345\210\235\351\230\266/3.python/160.exercises/config.json" create mode 100644 "data/1.dailycode\345\210\235\351\230\266/3.python/160.exercises/solution.json" create mode 100644 "data/1.dailycode\345\210\235\351\230\266/3.python/160.exercises/solution.md" create mode 100644 "data/1.dailycode\345\210\235\351\230\266/3.python/167.exercises/config.json" create mode 100644 "data/1.dailycode\345\210\235\351\230\266/3.python/167.exercises/solution.json" create mode 100644 "data/1.dailycode\345\210\235\351\230\266/3.python/167.exercises/solution.md" create mode 100644 "data/1.dailycode\345\210\235\351\230\266/3.python/168.exercises/config.json" create mode 100644 "data/1.dailycode\345\210\235\351\230\266/3.python/168.exercises/solution.json" create mode 100644 "data/1.dailycode\345\210\235\351\230\266/3.python/168.exercises/solution.md" create mode 100644 "data/1.dailycode\345\210\235\351\230\266/3.python/169.exercises/config.json" create mode 100644 "data/1.dailycode\345\210\235\351\230\266/3.python/169.exercises/solution.json" create mode 100644 "data/1.dailycode\345\210\235\351\230\266/3.python/169.exercises/solution.md" create mode 100644 "data/1.dailycode\345\210\235\351\230\266/3.python/171.exercises/config.json" create mode 100644 "data/1.dailycode\345\210\235\351\230\266/3.python/171.exercises/solution.json" create mode 100644 "data/1.dailycode\345\210\235\351\230\266/3.python/171.exercises/solution.md" create mode 100644 "data/1.dailycode\345\210\235\351\230\266/3.python/172.exercises/config.json" rename "data_source/exercises/\344\270\255\347\255\211/python/194.exercises/solution.json" => "data/1.dailycode\345\210\235\351\230\266/3.python/172.exercises/solution.json" (50%) create mode 100644 "data/1.dailycode\345\210\235\351\230\266/3.python/172.exercises/solution.md" create mode 100644 "data/1.dailycode\345\210\235\351\230\266/3.python/190.exercises/config.json" create mode 100644 "data/1.dailycode\345\210\235\351\230\266/3.python/190.exercises/solution.json" create mode 100644 "data/1.dailycode\345\210\235\351\230\266/3.python/190.exercises/solution.md" create mode 100644 "data/1.dailycode\345\210\235\351\230\266/3.python/191.exercises/config.json" rename "data_source/exercises/\344\270\255\347\255\211/python/192.exercises/solution.json" => "data/1.dailycode\345\210\235\351\230\266/3.python/191.exercises/solution.json" (66%) create mode 100644 "data/1.dailycode\345\210\235\351\230\266/3.python/191.exercises/solution.md" create mode 100644 "data/1.dailycode\345\210\235\351\230\266/3.python/202.exercises/config.json" create mode 100644 "data/1.dailycode\345\210\235\351\230\266/3.python/202.exercises/solution.json" create mode 100644 "data/1.dailycode\345\210\235\351\230\266/3.python/202.exercises/solution.md" create mode 100644 "data/1.dailycode\345\210\235\351\230\266/3.python/203.exercises/config.json" create mode 100644 "data/1.dailycode\345\210\235\351\230\266/3.python/203.exercises/solution.json" create mode 100644 "data/1.dailycode\345\210\235\351\230\266/3.python/203.exercises/solution.md" create mode 100644 "data/1.dailycode\345\210\235\351\230\266/3.python/204.exercises/config.json" create mode 100644 "data/1.dailycode\345\210\235\351\230\266/3.python/204.exercises/solution.json" create mode 100644 "data/1.dailycode\345\210\235\351\230\266/3.python/204.exercises/solution.md" create mode 100644 "data/1.dailycode\345\210\235\351\230\266/3.python/205.exercises/config.json" create mode 100644 "data/1.dailycode\345\210\235\351\230\266/3.python/205.exercises/solution.json" create mode 100644 "data/1.dailycode\345\210\235\351\230\266/3.python/205.exercises/solution.md" create mode 100644 "data/1.dailycode\345\210\235\351\230\266/3.python/206.exercises/config.json" create mode 100644 "data/1.dailycode\345\210\235\351\230\266/3.python/206.exercises/solution.json" create mode 100644 "data/1.dailycode\345\210\235\351\230\266/3.python/206.exercises/solution.md" create mode 100644 "data/1.dailycode\345\210\235\351\230\266/3.python/217.exercises/config.json" create mode 100644 "data/1.dailycode\345\210\235\351\230\266/3.python/217.exercises/solution.json" create mode 100644 "data/1.dailycode\345\210\235\351\230\266/3.python/217.exercises/solution.md" create mode 100644 "data/1.dailycode\345\210\235\351\230\266/3.python/219.exercises/config.json" create mode 100644 "data/1.dailycode\345\210\235\351\230\266/3.python/219.exercises/solution.json" create mode 100644 "data/1.dailycode\345\210\235\351\230\266/3.python/219.exercises/solution.md" create mode 100644 "data/1.dailycode\345\210\235\351\230\266/3.python/225.exercises/config.json" create mode 100644 "data/1.dailycode\345\210\235\351\230\266/3.python/225.exercises/solution.json" create mode 100644 "data/1.dailycode\345\210\235\351\230\266/3.python/225.exercises/solution.md" create mode 100644 "data/1.dailycode\345\210\235\351\230\266/3.python/226.exercises/config.json" create mode 100644 "data/1.dailycode\345\210\235\351\230\266/3.python/226.exercises/solution.json" create mode 100644 "data/1.dailycode\345\210\235\351\230\266/3.python/226.exercises/solution.md" create mode 100644 "data/1.dailycode\345\210\235\351\230\266/3.python/228.exercises/config.json" rename "data_source/exercises/\347\256\200\345\215\225/python/163.exercises/solution.json" => "data/1.dailycode\345\210\235\351\230\266/3.python/228.exercises/solution.json" (65%) create mode 100644 "data/1.dailycode\345\210\235\351\230\266/3.python/228.exercises/solution.md" create mode 100644 "data/1.dailycode\345\210\235\351\230\266/3.python/231.exercises/config.json" create mode 100644 "data/1.dailycode\345\210\235\351\230\266/3.python/231.exercises/solution.json" create mode 100644 "data/1.dailycode\345\210\235\351\230\266/3.python/231.exercises/solution.md" create mode 100644 "data/1.dailycode\345\210\235\351\230\266/3.python/232.exercises/config.json" create mode 100644 "data/1.dailycode\345\210\235\351\230\266/3.python/232.exercises/solution.json" create mode 100644 "data/1.dailycode\345\210\235\351\230\266/3.python/232.exercises/solution.md" create mode 100644 "data/1.dailycode\345\210\235\351\230\266/3.python/234.exercises/config.json" create mode 100644 "data/1.dailycode\345\210\235\351\230\266/3.python/234.exercises/solution.json" create mode 100644 "data/1.dailycode\345\210\235\351\230\266/3.python/234.exercises/solution.md" create mode 100644 "data/2.dailycode\344\270\255\351\230\266/3.python/102.exercises/config.json" create mode 100644 "data/2.dailycode\344\270\255\351\230\266/3.python/102.exercises/solution.json" create mode 100644 "data/2.dailycode\344\270\255\351\230\266/3.python/102.exercises/solution.md" create mode 100644 "data/2.dailycode\344\270\255\351\230\266/3.python/103.exercises/config.json" create mode 100644 "data/2.dailycode\344\270\255\351\230\266/3.python/103.exercises/solution.json" create mode 100644 "data/2.dailycode\344\270\255\351\230\266/3.python/103.exercises/solution.md" create mode 100644 "data/2.dailycode\344\270\255\351\230\266/3.python/105.exercises/config.json" create mode 100644 "data/2.dailycode\344\270\255\351\230\266/3.python/105.exercises/solution.json" create mode 100644 "data/2.dailycode\344\270\255\351\230\266/3.python/105.exercises/solution.md" create mode 100644 "data/2.dailycode\344\270\255\351\230\266/3.python/106.exercises/config.json" create mode 100644 "data/2.dailycode\344\270\255\351\230\266/3.python/106.exercises/solution.json" create mode 100644 "data/2.dailycode\344\270\255\351\230\266/3.python/106.exercises/solution.md" create mode 100644 "data/2.dailycode\344\270\255\351\230\266/3.python/107.exercises/config.json" create mode 100644 "data/2.dailycode\344\270\255\351\230\266/3.python/107.exercises/solution.json" create mode 100644 "data/2.dailycode\344\270\255\351\230\266/3.python/107.exercises/solution.md" create mode 100644 "data/2.dailycode\344\270\255\351\230\266/3.python/109.exercises/config.json" create mode 100644 "data/2.dailycode\344\270\255\351\230\266/3.python/109.exercises/solution.json" create mode 100644 "data/2.dailycode\344\270\255\351\230\266/3.python/109.exercises/solution.md" create mode 100644 "data/2.dailycode\344\270\255\351\230\266/3.python/113.exercises/config.json" create mode 100644 "data/2.dailycode\344\270\255\351\230\266/3.python/113.exercises/solution.json" create mode 100644 "data/2.dailycode\344\270\255\351\230\266/3.python/113.exercises/solution.md" create mode 100644 "data/2.dailycode\344\270\255\351\230\266/3.python/114.exercises/config.json" create mode 100644 "data/2.dailycode\344\270\255\351\230\266/3.python/114.exercises/solution.json" create mode 100644 "data/2.dailycode\344\270\255\351\230\266/3.python/114.exercises/solution.md" create mode 100644 "data/2.dailycode\344\270\255\351\230\266/3.python/116.exercises/config.json" create mode 100644 "data/2.dailycode\344\270\255\351\230\266/3.python/116.exercises/solution.json" create mode 100644 "data/2.dailycode\344\270\255\351\230\266/3.python/116.exercises/solution.md" create mode 100644 "data/2.dailycode\344\270\255\351\230\266/3.python/117.exercises/config.json" create mode 100644 "data/2.dailycode\344\270\255\351\230\266/3.python/117.exercises/solution.json" create mode 100644 "data/2.dailycode\344\270\255\351\230\266/3.python/117.exercises/solution.md" create mode 100644 "data/2.dailycode\344\270\255\351\230\266/3.python/120.exercises/config.json" create mode 100644 "data/2.dailycode\344\270\255\351\230\266/3.python/120.exercises/solution.json" create mode 100644 "data/2.dailycode\344\270\255\351\230\266/3.python/120.exercises/solution.md" create mode 100644 "data/2.dailycode\344\270\255\351\230\266/3.python/128.exercises/config.json" create mode 100644 "data/2.dailycode\344\270\255\351\230\266/3.python/128.exercises/solution.json" create mode 100644 "data/2.dailycode\344\270\255\351\230\266/3.python/128.exercises/solution.md" create mode 100644 "data/2.dailycode\344\270\255\351\230\266/3.python/129.exercises/config.json" create mode 100644 "data/2.dailycode\344\270\255\351\230\266/3.python/129.exercises/solution.json" create mode 100644 "data/2.dailycode\344\270\255\351\230\266/3.python/129.exercises/solution.md" create mode 100644 "data/2.dailycode\344\270\255\351\230\266/3.python/130.exercises/config.json" create mode 100644 "data/2.dailycode\344\270\255\351\230\266/3.python/130.exercises/solution.json" create mode 100644 "data/2.dailycode\344\270\255\351\230\266/3.python/130.exercises/solution.md" create mode 100644 "data/2.dailycode\344\270\255\351\230\266/3.python/131.exercises/config.json" create mode 100644 "data/2.dailycode\344\270\255\351\230\266/3.python/131.exercises/solution.json" create mode 100644 "data/2.dailycode\344\270\255\351\230\266/3.python/131.exercises/solution.md" create mode 100644 "data/2.dailycode\344\270\255\351\230\266/3.python/133.exercises/config.json" create mode 100644 "data/2.dailycode\344\270\255\351\230\266/3.python/133.exercises/solution.json" create mode 100644 "data/2.dailycode\344\270\255\351\230\266/3.python/133.exercises/solution.md" create mode 100644 "data/2.dailycode\344\270\255\351\230\266/3.python/134.exercises/config.json" create mode 100644 "data/2.dailycode\344\270\255\351\230\266/3.python/134.exercises/solution.json" create mode 100644 "data/2.dailycode\344\270\255\351\230\266/3.python/134.exercises/solution.md" create mode 100644 "data/2.dailycode\344\270\255\351\230\266/3.python/137.exercises/config.json" create mode 100644 "data/2.dailycode\344\270\255\351\230\266/3.python/137.exercises/solution.json" create mode 100644 "data/2.dailycode\344\270\255\351\230\266/3.python/137.exercises/solution.md" create mode 100644 "data/2.dailycode\344\270\255\351\230\266/3.python/138.exercises/config.json" create mode 100644 "data/2.dailycode\344\270\255\351\230\266/3.python/138.exercises/solution.json" create mode 100644 "data/2.dailycode\344\270\255\351\230\266/3.python/138.exercises/solution.md" create mode 100644 "data/2.dailycode\344\270\255\351\230\266/3.python/139.exercises/config.json" create mode 100644 "data/2.dailycode\344\270\255\351\230\266/3.python/139.exercises/solution.json" create mode 100644 "data/2.dailycode\344\270\255\351\230\266/3.python/139.exercises/solution.md" create mode 100644 "data/2.dailycode\344\270\255\351\230\266/3.python/142.exercises/config.json" create mode 100644 "data/2.dailycode\344\270\255\351\230\266/3.python/142.exercises/solution.json" create mode 100644 "data/2.dailycode\344\270\255\351\230\266/3.python/142.exercises/solution.md" create mode 100644 "data/2.dailycode\344\270\255\351\230\266/3.python/143.exercises/config.json" create mode 100644 "data/2.dailycode\344\270\255\351\230\266/3.python/143.exercises/solution.json" create mode 100644 "data/2.dailycode\344\270\255\351\230\266/3.python/143.exercises/solution.md" create mode 100644 "data/2.dailycode\344\270\255\351\230\266/3.python/146.exercises/config.json" create mode 100644 "data/2.dailycode\344\270\255\351\230\266/3.python/146.exercises/solution.json" create mode 100644 "data/2.dailycode\344\270\255\351\230\266/3.python/146.exercises/solution.md" create mode 100644 "data/2.dailycode\344\270\255\351\230\266/3.python/147.exercises/config.json" create mode 100644 "data/2.dailycode\344\270\255\351\230\266/3.python/147.exercises/solution.json" create mode 100644 "data/2.dailycode\344\270\255\351\230\266/3.python/147.exercises/solution.md" create mode 100644 "data/2.dailycode\344\270\255\351\230\266/3.python/148.exercises/config.json" create mode 100644 "data/2.dailycode\344\270\255\351\230\266/3.python/148.exercises/solution.json" create mode 100644 "data/2.dailycode\344\270\255\351\230\266/3.python/148.exercises/solution.md" create mode 100644 "data/2.dailycode\344\270\255\351\230\266/3.python/150.exercises/config.json" create mode 100644 "data/2.dailycode\344\270\255\351\230\266/3.python/150.exercises/solution.json" create mode 100644 "data/2.dailycode\344\270\255\351\230\266/3.python/150.exercises/solution.md" create mode 100644 "data/2.dailycode\344\270\255\351\230\266/3.python/151.exercises/config.json" rename "data_source/exercises/\344\270\255\347\255\211/python/186.exercises/solution.json" => "data/2.dailycode\344\270\255\351\230\266/3.python/151.exercises/solution.json" (68%) create mode 100644 "data/2.dailycode\344\270\255\351\230\266/3.python/151.exercises/solution.md" create mode 100644 "data/2.dailycode\344\270\255\351\230\266/3.python/152.exercises/config.json" create mode 100644 "data/2.dailycode\344\270\255\351\230\266/3.python/152.exercises/solution.json" create mode 100644 "data/2.dailycode\344\270\255\351\230\266/3.python/152.exercises/solution.md" create mode 100644 "data/2.dailycode\344\270\255\351\230\266/3.python/153.exercises/config.json" create mode 100644 "data/2.dailycode\344\270\255\351\230\266/3.python/153.exercises/solution.json" create mode 100644 "data/2.dailycode\344\270\255\351\230\266/3.python/153.exercises/solution.md" create mode 100644 "data/2.dailycode\344\270\255\351\230\266/3.python/162.exercises/config.json" create mode 100644 "data/2.dailycode\344\270\255\351\230\266/3.python/162.exercises/solution.json" create mode 100644 "data/2.dailycode\344\270\255\351\230\266/3.python/162.exercises/solution.md" create mode 100644 "data/2.dailycode\344\270\255\351\230\266/3.python/165.exercises/config.json" create mode 100644 "data/2.dailycode\344\270\255\351\230\266/3.python/165.exercises/solution.json" create mode 100644 "data/2.dailycode\344\270\255\351\230\266/3.python/165.exercises/solution.md" create mode 100644 "data/2.dailycode\344\270\255\351\230\266/3.python/166.exercises/config.json" create mode 100644 "data/2.dailycode\344\270\255\351\230\266/3.python/166.exercises/solution.json" create mode 100644 "data/2.dailycode\344\270\255\351\230\266/3.python/166.exercises/solution.md" create mode 100644 "data/2.dailycode\344\270\255\351\230\266/3.python/173.exercises/config.json" create mode 100644 "data/2.dailycode\344\270\255\351\230\266/3.python/173.exercises/solution.json" create mode 100644 "data/2.dailycode\344\270\255\351\230\266/3.python/173.exercises/solution.md" create mode 100644 "data/2.dailycode\344\270\255\351\230\266/3.python/179.exercises/config.json" create mode 100644 "data/2.dailycode\344\270\255\351\230\266/3.python/179.exercises/solution.json" create mode 100644 "data/2.dailycode\344\270\255\351\230\266/3.python/179.exercises/solution.md" create mode 100644 "data/2.dailycode\344\270\255\351\230\266/3.python/187.exercises/config.json" create mode 100644 "data/2.dailycode\344\270\255\351\230\266/3.python/187.exercises/solution.json" create mode 100644 "data/2.dailycode\344\270\255\351\230\266/3.python/187.exercises/solution.md" create mode 100644 "data/2.dailycode\344\270\255\351\230\266/3.python/189.exercises/config.json" create mode 100644 "data/2.dailycode\344\270\255\351\230\266/3.python/189.exercises/solution.json" create mode 100644 "data/2.dailycode\344\270\255\351\230\266/3.python/189.exercises/solution.md" create mode 100644 "data/2.dailycode\344\270\255\351\230\266/3.python/198.exercises/config.json" create mode 100644 "data/2.dailycode\344\270\255\351\230\266/3.python/198.exercises/solution.json" create mode 100644 "data/2.dailycode\344\270\255\351\230\266/3.python/198.exercises/solution.md" create mode 100644 "data/2.dailycode\344\270\255\351\230\266/3.python/199.exercises/config.json" create mode 100644 "data/2.dailycode\344\270\255\351\230\266/3.python/199.exercises/solution.json" create mode 100644 "data/2.dailycode\344\270\255\351\230\266/3.python/199.exercises/solution.md" create mode 100644 "data/2.dailycode\344\270\255\351\230\266/3.python/200.exercises/config.json" create mode 100644 "data/2.dailycode\344\270\255\351\230\266/3.python/200.exercises/solution.json" create mode 100644 "data/2.dailycode\344\270\255\351\230\266/3.python/200.exercises/solution.md" create mode 100644 "data/3.dailycode\351\253\230\351\230\266/3.python/115.exercises/config.json" create mode 100644 "data/3.dailycode\351\253\230\351\230\266/3.python/115.exercises/solution.json" create mode 100644 "data/3.dailycode\351\253\230\351\230\266/3.python/115.exercises/solution.md" create mode 100644 "data/3.dailycode\351\253\230\351\230\266/3.python/123.exercises/config.json" create mode 100644 "data/3.dailycode\351\253\230\351\230\266/3.python/123.exercises/solution.json" create mode 100644 "data/3.dailycode\351\253\230\351\230\266/3.python/123.exercises/solution.md" create mode 100644 "data/3.dailycode\351\253\230\351\230\266/3.python/124.exercises/config.json" create mode 100644 "data/3.dailycode\351\253\230\351\230\266/3.python/124.exercises/solution.json" create mode 100644 "data/3.dailycode\351\253\230\351\230\266/3.python/124.exercises/solution.md" create mode 100644 "data/3.dailycode\351\253\230\351\230\266/3.python/126.exercises/config.json" create mode 100644 "data/3.dailycode\351\253\230\351\230\266/3.python/126.exercises/solution.json" create mode 100644 "data/3.dailycode\351\253\230\351\230\266/3.python/126.exercises/solution.md" create mode 100644 "data/3.dailycode\351\253\230\351\230\266/3.python/127.exercises/config.json" create mode 100644 "data/3.dailycode\351\253\230\351\230\266/3.python/127.exercises/solution.json" create mode 100644 "data/3.dailycode\351\253\230\351\230\266/3.python/127.exercises/solution.md" create mode 100644 "data/3.dailycode\351\253\230\351\230\266/3.python/132.exercises/config.json" create mode 100644 "data/3.dailycode\351\253\230\351\230\266/3.python/132.exercises/solution.json" create mode 100644 "data/3.dailycode\351\253\230\351\230\266/3.python/132.exercises/solution.md" create mode 100644 "data/3.dailycode\351\253\230\351\230\266/3.python/135.exercises/config.json" create mode 100644 "data/3.dailycode\351\253\230\351\230\266/3.python/135.exercises/solution.json" create mode 100644 "data/3.dailycode\351\253\230\351\230\266/3.python/135.exercises/solution.md" create mode 100644 "data/3.dailycode\351\253\230\351\230\266/3.python/140.exercises/config.json" create mode 100644 "data/3.dailycode\351\253\230\351\230\266/3.python/140.exercises/solution.json" create mode 100644 "data/3.dailycode\351\253\230\351\230\266/3.python/140.exercises/solution.md" create mode 100644 "data/3.dailycode\351\253\230\351\230\266/3.python/149.exercises/config.json" create mode 100644 "data/3.dailycode\351\253\230\351\230\266/3.python/149.exercises/solution.json" create mode 100644 "data/3.dailycode\351\253\230\351\230\266/3.python/149.exercises/solution.md" create mode 100644 "data/3.dailycode\351\253\230\351\230\266/3.python/154.exercises/config.json" create mode 100644 "data/3.dailycode\351\253\230\351\230\266/3.python/154.exercises/solution.json" create mode 100644 "data/3.dailycode\351\253\230\351\230\266/3.python/154.exercises/solution.md" create mode 100644 "data/3.dailycode\351\253\230\351\230\266/3.python/164.exercises/config.json" create mode 100644 "data/3.dailycode\351\253\230\351\230\266/3.python/164.exercises/solution.json" create mode 100644 "data/3.dailycode\351\253\230\351\230\266/3.python/164.exercises/solution.md" create mode 100644 "data/3.dailycode\351\253\230\351\230\266/3.python/174.exercises/config.json" create mode 100644 "data/3.dailycode\351\253\230\351\230\266/3.python/174.exercises/solution.json" create mode 100644 "data/3.dailycode\351\253\230\351\230\266/3.python/174.exercises/solution.md" create mode 100644 "data/3.dailycode\351\253\230\351\230\266/3.python/188.exercises/config.json" create mode 100644 "data/3.dailycode\351\253\230\351\230\266/3.python/188.exercises/solution.json" create mode 100644 "data/3.dailycode\351\253\230\351\230\266/3.python/188.exercises/solution.md" create mode 100644 "data/3.dailycode\351\253\230\351\230\266/3.python/212.exercises/config.json" create mode 100644 "data/3.dailycode\351\253\230\351\230\266/3.python/212.exercises/solution.json" create mode 100644 "data/3.dailycode\351\253\230\351\230\266/3.python/212.exercises/solution.md" create mode 100644 "data/3.dailycode\351\253\230\351\230\266/3.python/214.exercises/config.json" create mode 100644 "data/3.dailycode\351\253\230\351\230\266/3.python/214.exercises/solution.json" create mode 100644 "data/3.dailycode\351\253\230\351\230\266/3.python/214.exercises/solution.md" create mode 100644 "data/3.dailycode\351\253\230\351\230\266/3.python/218.exercises/config.json" create mode 100644 "data/3.dailycode\351\253\230\351\230\266/3.python/218.exercises/solution.json" create mode 100644 "data/3.dailycode\351\253\230\351\230\266/3.python/218.exercises/solution.md" create mode 100644 "data/3.dailycode\351\253\230\351\230\266/3.python/224.exercises/config.json" create mode 100644 "data/3.dailycode\351\253\230\351\230\266/3.python/224.exercises/solution.json" create mode 100644 "data/3.dailycode\351\253\230\351\230\266/3.python/224.exercises/solution.md" create mode 100644 "data/3.dailycode\351\253\230\351\230\266/3.python/233.exercises/config.json" create mode 100644 "data/3.dailycode\351\253\230\351\230\266/3.python/233.exercises/solution.json" create mode 100644 "data/3.dailycode\351\253\230\351\230\266/3.python/233.exercises/solution.md" create mode 100644 "data/3.dailycode\351\253\230\351\230\266/3.python/239.exercises/config.json" create mode 100644 "data/3.dailycode\351\253\230\351\230\266/3.python/239.exercises/solution.json" create mode 100644 "data/3.dailycode\351\253\230\351\230\266/3.python/239.exercises/solution.md" create mode 100644 "data/3.dailycode\351\253\230\351\230\266/3.python/273.exercises/config.json" create mode 100644 "data/3.dailycode\351\253\230\351\230\266/3.python/273.exercises/solution.json" create mode 100644 "data/3.dailycode\351\253\230\351\230\266/3.python/273.exercises/solution.md" create mode 100644 "data/3.dailycode\351\253\230\351\230\266/3.python/282.exercises/config.json" create mode 100644 "data/3.dailycode\351\253\230\351\230\266/3.python/282.exercises/solution.json" create mode 100644 "data/3.dailycode\351\253\230\351\230\266/3.python/282.exercises/solution.md" create mode 100644 "data/3.dailycode\351\253\230\351\230\266/3.python/295.exercises/config.json" create mode 100644 "data/3.dailycode\351\253\230\351\230\266/3.python/295.exercises/solution.json" create mode 100644 "data/3.dailycode\351\253\230\351\230\266/3.python/295.exercises/solution.md" create mode 100644 "data/3.dailycode\351\253\230\351\230\266/3.python/297.exercises/config.json" create mode 100644 "data/3.dailycode\351\253\230\351\230\266/3.python/297.exercises/solution.json" create mode 100644 "data/3.dailycode\351\253\230\351\230\266/3.python/297.exercises/solution.md" create mode 100644 "data/3.dailycode\351\253\230\351\230\266/3.python/301.exercises/config.json" create mode 100644 "data/3.dailycode\351\253\230\351\230\266/3.python/301.exercises/solution.json" create mode 100644 "data/3.dailycode\351\253\230\351\230\266/3.python/301.exercises/solution.md" create mode 100644 "data/3.dailycode\351\253\230\351\230\266/3.python/312.exercises/config.json" create mode 100644 "data/3.dailycode\351\253\230\351\230\266/3.python/312.exercises/solution.json" create mode 100644 "data/3.dailycode\351\253\230\351\230\266/3.python/312.exercises/solution.md" create mode 100644 "data/3.dailycode\351\253\230\351\230\266/3.python/315.exercises/config.json" create mode 100644 "data/3.dailycode\351\253\230\351\230\266/3.python/315.exercises/solution.json" create mode 100644 "data/3.dailycode\351\253\230\351\230\266/3.python/315.exercises/solution.md" create mode 100644 "data/3.dailycode\351\253\230\351\230\266/3.python/321.exercises/config.json" create mode 100644 "data/3.dailycode\351\253\230\351\230\266/3.python/321.exercises/solution.json" create mode 100644 "data/3.dailycode\351\253\230\351\230\266/3.python/321.exercises/solution.md" create mode 100644 "data/3.dailycode\351\253\230\351\230\266/3.python/327.exercises/config.json" create mode 100644 "data/3.dailycode\351\253\230\351\230\266/3.python/327.exercises/solution.json" create mode 100644 "data/3.dailycode\351\253\230\351\230\266/3.python/327.exercises/solution.md" create mode 100644 "data/3.dailycode\351\253\230\351\230\266/3.python/329.exercises/config.json" rename "data_source/exercises/\345\233\260\351\232\276/python/269.exercises/solution.json" => "data/3.dailycode\351\253\230\351\230\266/3.python/329.exercises/solution.json" (61%) create mode 100644 "data/3.dailycode\351\253\230\351\230\266/3.python/329.exercises/solution.md" create mode 100644 "data/3.dailycode\351\253\230\351\230\266/3.python/330.exercises/config.json" create mode 100644 "data/3.dailycode\351\253\230\351\230\266/3.python/330.exercises/solution.json" create mode 100644 "data/3.dailycode\351\253\230\351\230\266/3.python/330.exercises/solution.md" create mode 100644 "data/3.dailycode\351\253\230\351\230\266/3.python/335.exercises/config.json" create mode 100644 "data/3.dailycode\351\253\230\351\230\266/3.python/335.exercises/solution.json" create mode 100644 "data/3.dailycode\351\253\230\351\230\266/3.python/335.exercises/solution.md" create mode 100644 "data/3.dailycode\351\253\230\351\230\266/3.python/336.exercises/config.json" create mode 100644 "data/3.dailycode\351\253\230\351\230\266/3.python/336.exercises/solution.json" create mode 100644 "data/3.dailycode\351\253\230\351\230\266/3.python/336.exercises/solution.md" create mode 100644 "data/3.dailycode\351\253\230\351\230\266/3.python/352.exercises/config.json" create mode 100644 "data/3.dailycode\351\253\230\351\230\266/3.python/352.exercises/solution.json" create mode 100644 "data/3.dailycode\351\253\230\351\230\266/3.python/352.exercises/solution.md" create mode 100644 "data/3.dailycode\351\253\230\351\230\266/3.python/354.exercises/config.json" create mode 100644 "data/3.dailycode\351\253\230\351\230\266/3.python/354.exercises/solution.json" create mode 100644 "data/3.dailycode\351\253\230\351\230\266/3.python/354.exercises/solution.md" create mode 100644 "data/3.dailycode\351\253\230\351\230\266/3.python/363.exercises/config.json" create mode 100644 "data/3.dailycode\351\253\230\351\230\266/3.python/363.exercises/solution.json" create mode 100644 "data/3.dailycode\351\253\230\351\230\266/3.python/363.exercises/solution.md" create mode 100644 "data/3.dailycode\351\253\230\351\230\266/3.python/381.exercises/config.json" create mode 100644 "data/3.dailycode\351\253\230\351\230\266/3.python/381.exercises/solution.json" create mode 100644 "data/3.dailycode\351\253\230\351\230\266/3.python/381.exercises/solution.md" delete mode 100644 "data_source/exercises/\344\270\255\347\255\211/python/156.exercises/solution.md" delete mode 100644 "data_source/exercises/\344\270\255\347\255\211/python/159.exercises/solution.json" delete mode 100644 "data_source/exercises/\344\270\255\347\255\211/python/159.exercises/solution.md" delete mode 100644 "data_source/exercises/\344\270\255\347\255\211/python/161.exercises/solution.md" delete mode 100644 "data_source/exercises/\344\270\255\347\255\211/python/177.exercises/solution.json" delete mode 100644 "data_source/exercises/\344\270\255\347\255\211/python/177.exercises/solution.md" delete mode 100644 "data_source/exercises/\344\270\255\347\255\211/python/178.exercises/config.json" delete mode 100644 "data_source/exercises/\344\270\255\347\255\211/python/178.exercises/solution.json" delete mode 100644 "data_source/exercises/\344\270\255\347\255\211/python/178.exercises/solution.md" delete mode 100644 "data_source/exercises/\344\270\255\347\255\211/python/180.exercises/config.json" delete mode 100644 "data_source/exercises/\344\270\255\347\255\211/python/180.exercises/solution.json" delete mode 100644 "data_source/exercises/\344\270\255\347\255\211/python/180.exercises/solution.md" delete mode 100644 "data_source/exercises/\344\270\255\347\255\211/python/184.exercises/config.json" delete mode 100644 "data_source/exercises/\344\270\255\347\255\211/python/184.exercises/solution.json" delete mode 100644 "data_source/exercises/\344\270\255\347\255\211/python/184.exercises/solution.md" delete mode 100644 "data_source/exercises/\344\270\255\347\255\211/python/186.exercises/config.json" delete mode 100644 "data_source/exercises/\344\270\255\347\255\211/python/186.exercises/solution.md" delete mode 100644 "data_source/exercises/\344\270\255\347\255\211/python/192.exercises/config.json" delete mode 100644 "data_source/exercises/\344\270\255\347\255\211/python/192.exercises/solution.md" delete mode 100644 "data_source/exercises/\344\270\255\347\255\211/python/194.exercises/config.json" delete mode 100644 "data_source/exercises/\344\270\255\347\255\211/python/194.exercises/solution.md" delete mode 100644 "data_source/exercises/\345\233\260\351\232\276/python/158.exercises/config.json" delete mode 100644 "data_source/exercises/\345\233\260\351\232\276/python/158.exercises/solution.json" delete mode 100644 "data_source/exercises/\345\233\260\351\232\276/python/158.exercises/solution.md" delete mode 100644 "data_source/exercises/\345\233\260\351\232\276/python/185.exercises/config.json" delete mode 100644 "data_source/exercises/\345\233\260\351\232\276/python/185.exercises/solution.json" delete mode 100644 "data_source/exercises/\345\233\260\351\232\276/python/185.exercises/solution.md" delete mode 100644 "data_source/exercises/\345\233\260\351\232\276/python/248.exercises/config.json" delete mode 100644 "data_source/exercises/\345\233\260\351\232\276/python/248.exercises/solution.json" delete mode 100644 "data_source/exercises/\345\233\260\351\232\276/python/248.exercises/solution.md" delete mode 100644 "data_source/exercises/\345\233\260\351\232\276/python/262.exercises/config.json" delete mode 100644 "data_source/exercises/\345\233\260\351\232\276/python/262.exercises/solution.json" delete mode 100644 "data_source/exercises/\345\233\260\351\232\276/python/262.exercises/solution.md" delete mode 100644 "data_source/exercises/\345\233\260\351\232\276/python/265.exercises/config.json" delete mode 100644 "data_source/exercises/\345\233\260\351\232\276/python/265.exercises/solution.md" delete mode 100644 "data_source/exercises/\345\233\260\351\232\276/python/269.exercises/config.json" delete mode 100644 "data_source/exercises/\345\233\260\351\232\276/python/269.exercises/solution.md" delete mode 100644 "data_source/exercises/\345\233\260\351\232\276/python/272.exercises/config.json" delete mode 100644 "data_source/exercises/\345\233\260\351\232\276/python/272.exercises/solution.json" delete mode 100644 "data_source/exercises/\345\233\260\351\232\276/python/272.exercises/solution.md" delete mode 100644 "data_source/exercises/\345\233\260\351\232\276/python/296.exercises/config.json" delete mode 100644 "data_source/exercises/\345\233\260\351\232\276/python/296.exercises/solution.json" delete mode 100644 "data_source/exercises/\345\233\260\351\232\276/python/296.exercises/solution.md" delete mode 100644 "data_source/exercises/\345\233\260\351\232\276/python/302.exercises/config.json" delete mode 100644 "data_source/exercises/\345\233\260\351\232\276/python/302.exercises/solution.json" delete mode 100644 "data_source/exercises/\345\233\260\351\232\276/python/302.exercises/solution.md" delete mode 100644 "data_source/exercises/\345\233\260\351\232\276/python/305.exercises/config.json" delete mode 100644 "data_source/exercises/\345\233\260\351\232\276/python/305.exercises/solution.json" delete mode 100644 "data_source/exercises/\345\233\260\351\232\276/python/305.exercises/solution.md" delete mode 100644 "data_source/exercises/\345\233\260\351\232\276/python/308.exercises/config.json" delete mode 100644 "data_source/exercises/\345\233\260\351\232\276/python/308.exercises/solution.json" delete mode 100644 "data_source/exercises/\345\233\260\351\232\276/python/308.exercises/solution.md" delete mode 100644 "data_source/exercises/\345\233\260\351\232\276/python/317.exercises/config.json" delete mode 100644 "data_source/exercises/\345\233\260\351\232\276/python/317.exercises/solution.json" delete mode 100644 "data_source/exercises/\345\233\260\351\232\276/python/317.exercises/solution.md" delete mode 100644 "data_source/exercises/\345\233\260\351\232\276/python/358.exercises/config.json" delete mode 100644 "data_source/exercises/\345\233\260\351\232\276/python/358.exercises/solution.json" delete mode 100644 "data_source/exercises/\345\233\260\351\232\276/python/358.exercises/solution.md" delete mode 100644 "data_source/exercises/\347\256\200\345\215\225/python/157.exercises/config.json" delete mode 100644 "data_source/exercises/\347\256\200\345\215\225/python/157.exercises/solution.json" delete mode 100644 "data_source/exercises/\347\256\200\345\215\225/python/157.exercises/solution.md" delete mode 100644 "data_source/exercises/\347\256\200\345\215\225/python/163.exercises/config.json" delete mode 100644 "data_source/exercises/\347\256\200\345\215\225/python/163.exercises/solution.md" delete mode 100644 "data_source/exercises/\347\256\200\345\215\225/python/170.exercises/config.json" delete mode 100644 "data_source/exercises/\347\256\200\345\215\225/python/170.exercises/solution.json" delete mode 100644 "data_source/exercises/\347\256\200\345\215\225/python/170.exercises/solution.md" delete mode 100644 "data_source/exercises/\347\256\200\345\215\225/python/175.exercises/config.json" delete mode 100644 "data_source/exercises/\347\256\200\345\215\225/python/175.exercises/solution.json" delete mode 100644 "data_source/exercises/\347\256\200\345\215\225/python/175.exercises/solution.md" delete mode 100644 "data_source/exercises/\347\256\200\345\215\225/python/176.exercises/config.json" delete mode 100644 "data_source/exercises/\347\256\200\345\215\225/python/176.exercises/solution.json" delete mode 100644 "data_source/exercises/\347\256\200\345\215\225/python/176.exercises/solution.md" delete mode 100644 "data_source/exercises/\347\256\200\345\215\225/python/181.exercises/config.json" delete mode 100644 "data_source/exercises/\347\256\200\345\215\225/python/181.exercises/solution.json" delete mode 100644 "data_source/exercises/\347\256\200\345\215\225/python/181.exercises/solution.md" delete mode 100644 "data_source/exercises/\347\256\200\345\215\225/python/182.exercises/config.json" delete mode 100644 "data_source/exercises/\347\256\200\345\215\225/python/182.exercises/solution.json" delete mode 100644 "data_source/exercises/\347\256\200\345\215\225/python/182.exercises/solution.md" delete mode 100644 "data_source/exercises/\347\256\200\345\215\225/python/183.exercises/config.json" delete mode 100644 "data_source/exercises/\347\256\200\345\215\225/python/183.exercises/solution.json" delete mode 100644 "data_source/exercises/\347\256\200\345\215\225/python/183.exercises/solution.md" delete mode 100644 "data_source/exercises/\347\256\200\345\215\225/python/193.exercises/config.json" delete mode 100644 "data_source/exercises/\347\256\200\345\215\225/python/193.exercises/solution.json" delete mode 100644 "data_source/exercises/\347\256\200\345\215\225/python/193.exercises/solution.md" delete mode 100644 "data_source/exercises/\347\256\200\345\215\225/python/195.exercises/config.json" delete mode 100644 "data_source/exercises/\347\256\200\345\215\225/python/195.exercises/solution.json" delete mode 100644 "data_source/exercises/\347\256\200\345\215\225/python/195.exercises/solution.md" delete mode 100644 "data_source/exercises/\347\256\200\345\215\225/python/196.exercises/config.json" delete mode 100644 "data_source/exercises/\347\256\200\345\215\225/python/196.exercises/solution.json" delete mode 100644 "data_source/exercises/\347\256\200\345\215\225/python/196.exercises/solution.md" delete mode 100644 "data_source/exercises/\347\256\200\345\215\225/python/197.exercises/config.json" delete mode 100644 "data_source/exercises/\347\256\200\345\215\225/python/197.exercises/solution.json" delete mode 100644 "data_source/exercises/\347\256\200\345\215\225/python/197.exercises/solution.md" diff --git "a/data_source/exercises/\344\270\255\347\255\211/python/156.exercises/config.json" "b/data/1.dailycode\345\210\235\351\230\266/3.python/101.exercises/config.json" similarity index 67% rename from "data_source/exercises/\344\270\255\347\255\211/python/156.exercises/config.json" rename to "data/1.dailycode\345\210\235\351\230\266/3.python/101.exercises/config.json" index 0cb618f7..3cf5d365 100644 --- "a/data_source/exercises/\344\270\255\347\255\211/python/156.exercises/config.json" +++ "b/data/1.dailycode\345\210\235\351\230\266/3.python/101.exercises/config.json" @@ -1,5 +1,5 @@ { - "node_id": "dailycode-eab0b681e8ab4258a3286cf1d7642d64", + "node_id": "dailycode-857b20ebfd244d708b1010bbecd88556", "keywords": [], "children": [], "keywords_must": [], diff --git "a/data/1.dailycode\345\210\235\351\230\266/3.python/101.exercises/solution.json" "b/data/1.dailycode\345\210\235\351\230\266/3.python/101.exercises/solution.json" new file mode 100644 index 00000000..c38d0712 --- /dev/null +++ "b/data/1.dailycode\345\210\235\351\230\266/3.python/101.exercises/solution.json" @@ -0,0 +1,7 @@ +{ + "type": "code_options", + "source": "solution.md", + "exercise_id": "596d96c92b4b46c39c8f9a5731941081", + "author": "csdn.net", + "keywords": "树,深度优先搜索,广度优先搜索,二叉树" +} \ No newline at end of file diff --git "a/data/1.dailycode\345\210\235\351\230\266/3.python/101.exercises/solution.md" "b/data/1.dailycode\345\210\235\351\230\266/3.python/101.exercises/solution.md" new file mode 100644 index 00000000..b5eb7501 --- /dev/null +++ "b/data/1.dailycode\345\210\235\351\230\266/3.python/101.exercises/solution.md" @@ -0,0 +1,82 @@ +# 对称二叉树 + +
给定一个二叉树,检查它是否是镜像对称的。
+ ++ +
例如,二叉树 [1,2,2,3,4,4,3]
是对称的。
1 + / \ + 2 2 + / \ / \ +3 4 4 3 ++ +
+ +
但是下面这个 [1,2,2,null,3,null,3]
则不是镜像对称的:
1 + / \ + 2 2 + \ \ + 3 3 ++ +
+ +
进阶:
+ +你可以运用递归和迭代两种方法解决这个问题吗?
+ + +## template + +```python +class TreeNode: + def __init__(self, x): + self.val = x + self.left = None + self.right = None + + +class Solution: + + def isSymmetric(self, root: TreeNode) -> bool: + def judge(left, right): + if not left and not right: + return True + elif not left or not right: + return False + else: + return left.val == right.val and judge(left.right, right.left) and judge(left.left, right.right) + + return judge(root, root) +``` + +## 答案 + +```python + +``` + +## 选项 + +### A + +```python + +``` + +### B + +```python + +``` + +### C + +```python + +``` \ No newline at end of file diff --git "a/data_source/exercises/\344\270\255\347\255\211/python/161.exercises/config.json" "b/data/1.dailycode\345\210\235\351\230\266/3.python/104.exercises/config.json" similarity index 67% rename from "data_source/exercises/\344\270\255\347\255\211/python/161.exercises/config.json" rename to "data/1.dailycode\345\210\235\351\230\266/3.python/104.exercises/config.json" index cbbc59d2..0fcc3228 100644 --- "a/data_source/exercises/\344\270\255\347\255\211/python/161.exercises/config.json" +++ "b/data/1.dailycode\345\210\235\351\230\266/3.python/104.exercises/config.json" @@ -1,5 +1,5 @@ { - "node_id": "dailycode-93691725213e43c3a260aeb9f012cd04", + "node_id": "dailycode-fffbbc837b574bf8b24cc5dbf815e374", "keywords": [], "children": [], "keywords_must": [], diff --git "a/data/1.dailycode\345\210\235\351\230\266/3.python/104.exercises/solution.json" "b/data/1.dailycode\345\210\235\351\230\266/3.python/104.exercises/solution.json" new file mode 100644 index 00000000..c64b9b0c --- /dev/null +++ "b/data/1.dailycode\345\210\235\351\230\266/3.python/104.exercises/solution.json" @@ -0,0 +1,7 @@ +{ + "type": "code_options", + "source": "solution.md", + "exercise_id": "1a8b3997ea044b9aa0fc4b4c425c39a5", + "author": "csdn.net", + "keywords": "树,深度优先搜索,广度优先搜索,二叉树" +} \ No newline at end of file diff --git "a/data/1.dailycode\345\210\235\351\230\266/3.python/104.exercises/solution.md" "b/data/1.dailycode\345\210\235\351\230\266/3.python/104.exercises/solution.md" new file mode 100644 index 00000000..85f30f16 --- /dev/null +++ "b/data/1.dailycode\345\210\235\351\230\266/3.python/104.exercises/solution.md" @@ -0,0 +1,63 @@ +# 二叉树的最大深度 + +给定一个二叉树,找出其最大深度。
+ +二叉树的深度为根节点到最远叶子节点的最长路径上的节点数。
+ +说明: 叶子节点是指没有子节点的节点。
+ +示例:
+给定二叉树 [3,9,20,null,null,15,7]
,
3 + / \ + 9 20 + / \ + 15 7+ +
返回它的最大深度 3 。
+ + +## template + +```python +class TreeNode: + def __init__(self, x): + self.val = x + self.left = None + self.right = None + +class Solution: + def maxDepth(self, root: TreeNode) -> int: + if root is None: + return 0 + maxdepth = max(self.maxDepth(root.left),self.maxDepth(root.right)) + 1 + return maxdepth + +``` + +## 答案 + +```python + +``` + +## 选项 + +### A + +```python + +``` + +### B + +```python + +``` + +### C + +```python + +``` \ No newline at end of file diff --git "a/data_source/exercises/\344\270\255\347\255\211/python/177.exercises/config.json" "b/data/1.dailycode\345\210\235\351\230\266/3.python/108.exercises/config.json" similarity index 67% rename from "data_source/exercises/\344\270\255\347\255\211/python/177.exercises/config.json" rename to "data/1.dailycode\345\210\235\351\230\266/3.python/108.exercises/config.json" index 1c947142..8923fb08 100644 --- "a/data_source/exercises/\344\270\255\347\255\211/python/177.exercises/config.json" +++ "b/data/1.dailycode\345\210\235\351\230\266/3.python/108.exercises/config.json" @@ -1,5 +1,5 @@ { - "node_id": "dailycode-11b18eef90c24b0dbb4e062de3ebfe75", + "node_id": "dailycode-d7b84e9a9afd4d659afb4a7f453180aa", "keywords": [], "children": [], "keywords_must": [], diff --git "a/data/1.dailycode\345\210\235\351\230\266/3.python/108.exercises/solution.json" "b/data/1.dailycode\345\210\235\351\230\266/3.python/108.exercises/solution.json" new file mode 100644 index 00000000..1a75b906 --- /dev/null +++ "b/data/1.dailycode\345\210\235\351\230\266/3.python/108.exercises/solution.json" @@ -0,0 +1,7 @@ +{ + "type": "code_options", + "source": "solution.md", + "exercise_id": "418607231ee44c04bf6bbb9e29f3ad69", + "author": "csdn.net", + "keywords": "树,二叉搜索树,数组,分治,二叉树" +} \ No newline at end of file diff --git "a/data/1.dailycode\345\210\235\351\230\266/3.python/108.exercises/solution.md" "b/data/1.dailycode\345\210\235\351\230\266/3.python/108.exercises/solution.md" new file mode 100644 index 00000000..ebc0d0fd --- /dev/null +++ "b/data/1.dailycode\345\210\235\351\230\266/3.python/108.exercises/solution.md" @@ -0,0 +1,89 @@ +# 将有序数组转换为二叉搜索树 + +给你一个整数数组 nums
,其中元素已经按 升序 排列,请你将其转换为一棵 高度平衡 二叉搜索树。
高度平衡 二叉树是一棵满足「每个节点的左右两个子树的高度差的绝对值不超过 1 」的二叉树。
+ ++ +
示例 1:
+ ++输入:nums = [-10,-3,0,5,9] +输出:[0,-3,9,-10,null,5] +解释:[0,-10,5,null,-3,null,9] 也将被视为正确答案: + ++ +
示例 2:
+ ++输入:nums = [1,3] +输出:[3,1] +解释:[1,3] 和 [3,1] 都是高度平衡二叉搜索树。 ++ +
+ +
提示:
+ +1 <= nums.length <= 104
-104 <= nums[i] <= 104
nums
按 严格递增 顺序排列给定一个二叉树,判断它是否是高度平衡的二叉树。
+ +本题中,一棵高度平衡二叉树定义为:
+ +++ +一个二叉树每个节点 的左右两个子树的高度差的绝对值不超过 1 。
+
+ +
示例 1:
+ ++输入:root = [3,9,20,null,null,15,7] +输出:true ++ +
示例 2:
+ ++输入:root = [1,2,2,3,3,null,null,4,4] +输出:false ++ +
示例 3:
+ ++输入:root = [] +输出:true ++ +
+ +
提示:
+ +[0, 5000]
内-104 <= Node.val <= 104
给定一个二叉树,找出其最小深度。
+ +最小深度是从根节点到最近叶子节点的最短路径上的节点数量。
+ +说明:叶子节点是指没有子节点的节点。
+ ++ +
示例 1:
+ ++输入:root = [3,9,20,null,null,15,7] +输出:2 ++ +
示例 2:
+ ++输入:root = [2,null,3,null,4,null,5,null,6] +输出:5 ++ +
+ +
提示:
+ +[0, 105]
内-1000 <= Node.val <= 1000
给你二叉树的根节点 root
和一个表示目标和的整数 targetSum
,判断该树中是否存在 根节点到叶子节点 的路径,这条路径上所有节点值相加等于目标和 targetSum
。
叶子节点 是指没有子节点的节点。
+ ++ +
示例 1:
+ ++输入:root = [5,4,8,11,null,13,4,7,2,null,null,null,1], targetSum = 22 +输出:true ++ +
示例 2:
+ ++输入:root = [1,2,3], targetSum = 5 +输出:false ++ +
示例 3:
+ ++输入:root = [1,2], targetSum = 0 +输出:false ++ +
+ +
提示:
+ +[0, 5000]
内-1000 <= Node.val <= 1000
-1000 <= targetSum <= 1000
给定一个非负整数 numRows
,生成「杨辉三角」的前 numRows
行。
在「杨辉三角」中,每个数是它左上方和右上方的数的和。
+ + + ++ +
示例 1:
+ ++输入: numRows = 5 +输出: [[1],[1,1],[1,2,1],[1,3,3,1],[1,4,6,4,1]] ++ +
示例 2:
+ ++输入: numRows = 1 +输出: [[1]] ++ +
+ +
提示:
+ +1 <= numRows <= 30
给定一个非负索引 rowIndex
,返回「杨辉三角」的第 rowIndex
行。
在「杨辉三角」中,每个数是它左上方和右上方的数的和。
+ + + ++ +
示例 1:
+ ++输入: rowIndex = 3 +输出: [1,3,3,1] ++ +
示例 2:
+ ++输入: rowIndex = 0 +输出: [1] ++ +
示例 3:
+ ++输入: rowIndex = 1 +输出: [1,1] ++ +
+ +
提示:
+ +0 <= rowIndex <= 33
+ +
进阶:
+ +你可以优化你的算法到 O(rowIndex)
空间复杂度吗?
给定一个数组 prices
,它的第 i
个元素 prices[i]
表示一支给定股票第 i
天的价格。
你只能选择 某一天 买入这只股票,并选择在 未来的某一个不同的日子 卖出该股票。设计一个算法来计算你所能获取的最大利润。
+ +返回你可以从这笔交易中获取的最大利润。如果你不能获取任何利润,返回 0
。
+ +
示例 1:
+ ++输入:[7,1,5,3,6,4] +输出:5 +解释:在第 2 天(股票价格 = 1)的时候买入,在第 5 天(股票价格 = 6)的时候卖出,最大利润 = 6-1 = 5 。 + 注意利润不能是 7-1 = 6, 因为卖出价格需要大于买入价格;同时,你不能在买入前卖出股票。 ++ +
示例 2:
+ ++输入:prices = [7,6,4,3,1] +输出:0 +解释:在这种情况下, 没有交易完成, 所以最大利润为 0。 ++ +
+ +
提示:
+ +1 <= prices.length <= 105
0 <= prices[i] <= 104
给定一个数组 prices
,其中 prices[i]
是一支给定股票第 i
天的价格。
设计一个算法来计算你所能获取的最大利润。你可以尽可能地完成更多的交易(多次买卖一支股票)。
+ +注意:你不能同时参与多笔交易(你必须在再次购买前出售掉之前的股票)。
+ ++ +
示例 1:
+ ++输入: prices = [7,1,5,3,6,4] +输出: 7 +解释: 在第 2 天(股票价格 = 1)的时候买入,在第 3 天(股票价格 = 5)的时候卖出, 这笔交易所能获得利润 = 5-1 = 4 。 + 随后,在第 4 天(股票价格 = 3)的时候买入,在第 5 天(股票价格 = 6)的时候卖出, 这笔交易所能获得利润 = 6-3 = 3 。 ++ +
示例 2:
+ ++输入: prices = [1,2,3,4,5] +输出: 4 +解释: 在第 1 天(股票价格 = 1)的时候买入,在第 5 天 (股票价格 = 5)的时候卖出, 这笔交易所能获得利润 = 5-1 = 4 。 + 注意你不能在第 1 天和第 2 天接连购买股票,之后再将它们卖出。因为这样属于同时参与了多笔交易,你必须在再次购买前出售掉之前的股票。 ++ +
示例 3:
+ ++输入: prices = [7,6,4,3,1] +输出: 0 +解释: 在这种情况下, 没有交易完成, 所以最大利润为 0。+ +
+ +
提示:
+ +1 <= prices.length <= 3 * 104
0 <= prices[i] <= 104
给定一个字符串,验证它是否是回文串,只考虑字母和数字字符,可以忽略字母的大小写。
+ +说明:本题中,我们将空字符串定义为有效的回文串。
+ ++ +
示例 1:
+ ++输入: "A man, a plan, a canal: Panama" +输出: true +解释:"amanaplanacanalpanama" 是回文串 ++ +
示例 2:
+ ++输入: "race a car" +输出: false +解释:"raceacar" 不是回文串 ++ +
+ +
提示:
+ +1 <= s.length <= 2 * 105
s
由 ASCII 字符组成给定一个非空整数数组,除了某个元素只出现一次以外,其余每个元素均出现两次。找出那个只出现了一次的元素。
+ +说明:
+ +你的算法应该具有线性时间复杂度。 你可以不使用额外空间来实现吗?
+ +示例 1:
+ +输入: [2,2,1] +输出: 1 ++ +
示例 2:
+ +输入: [4,1,2,1,2] +输出: 4+ + +## template + +```python +class Solution: + def singleNumber(self, nums: List[int]) -> int: + nums = sorted(nums) + i = 0 + while i < len(nums) - 1: + if nums[i] == nums[i + 1]: + i += 2 + else: + return nums[i] + return nums[i] + +``` + +## 答案 + +```python + +``` + +## 选项 + +### A + +```python + +``` + +### B + +```python + +``` + +### C + +```python + +``` \ No newline at end of file diff --git "a/data/1.dailycode\345\210\235\351\230\266/3.python/141.exercises/config.json" "b/data/1.dailycode\345\210\235\351\230\266/3.python/141.exercises/config.json" new file mode 100644 index 00000000..5ee306d0 --- /dev/null +++ "b/data/1.dailycode\345\210\235\351\230\266/3.python/141.exercises/config.json" @@ -0,0 +1,10 @@ +{ + "node_id": "dailycode-f38f728eb8ce496791f8904f6a664173", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [], + "export": [ + "solution.json" + ] +} \ No newline at end of file diff --git "a/data/1.dailycode\345\210\235\351\230\266/3.python/141.exercises/solution.json" "b/data/1.dailycode\345\210\235\351\230\266/3.python/141.exercises/solution.json" new file mode 100644 index 00000000..b2805c64 --- /dev/null +++ "b/data/1.dailycode\345\210\235\351\230\266/3.python/141.exercises/solution.json" @@ -0,0 +1,7 @@ +{ + "type": "code_options", + "source": "solution.md", + "exercise_id": "c1ed8b0c386f4957a33dae2b72214ebc", + "author": "csdn.net", + "keywords": "哈希表,链表,双指针" +} \ No newline at end of file diff --git "a/data/1.dailycode\345\210\235\351\230\266/3.python/141.exercises/solution.md" "b/data/1.dailycode\345\210\235\351\230\266/3.python/141.exercises/solution.md" new file mode 100644 index 00000000..1f1b4ca4 --- /dev/null +++ "b/data/1.dailycode\345\210\235\351\230\266/3.python/141.exercises/solution.md" @@ -0,0 +1,103 @@ +# 环形链表 + +
给定一个链表,判断链表中是否有环。
+ +如果链表中有某个节点,可以通过连续跟踪 next
指针再次到达,则链表中存在环。 为了表示给定链表中的环,我们使用整数 pos
来表示链表尾连接到链表中的位置(索引从 0 开始)。 如果 pos
是 -1
,则在该链表中没有环。注意:pos
不作为参数进行传递,仅仅是为了标识链表的实际情况。
如果链表中存在环,则返回 true
。 否则,返回 false
。
+ +
进阶:
+ +你能用 O(1)(即,常量)内存解决此问题吗?
+ ++ +
示例 1:
+ + + +输入:head = [3,2,0,-4], pos = 1 +输出:true +解释:链表中有一个环,其尾部连接到第二个节点。 ++ +
示例 2:
+ + + +输入:head = [1,2], pos = 0 +输出:true +解释:链表中有一个环,其尾部连接到第一个节点。 ++ +
示例 3:
+ + + +输入:head = [1], pos = -1 +输出:false +解释:链表中没有环。 ++ +
+ +
提示:
+ +[0, 104]
-105 <= Node.val <= 105
pos
为 -1
或者链表中的一个 有效索引 。给你二叉树的根节点 root
,返回它节点值的 前序 遍历。
+ +
示例 1:
+ ++输入:root = [1,null,2,3] +输出:[1,2,3] ++ +
示例 2:
+ ++输入:root = [] +输出:[] ++ +
示例 3:
+ ++输入:root = [1] +输出:[1] ++ +
示例 4:
+ ++输入:root = [1,2] +输出:[1,2] ++ +
示例 5:
+ ++输入:root = [1,null,2] +输出:[1,2] ++ +
+ +
提示:
+ +[0, 100]
内-100 <= Node.val <= 100
+ +
进阶:递归算法很简单,你可以通过迭代算法完成吗?
+ + +## template + +```python +class TreeNode: + def __init__(self, x): + self.val = x + self.left = None + self.right = None + + +class Solution: + def __init__(self): + self.ans = [] + + def preorderTraversal(self, root: TreeNode) -> List[int]: + if not root: + return [] + self.ans.append(root.val) + self.preorderTraversal(root.left) + self.preorderTraversal(root.right) + return self.ans + +``` + +## 答案 + +```python + +``` + +## 选项 + +### A + +```python + +``` + +### B + +```python + +``` + +### C + +```python + +``` \ No newline at end of file diff --git "a/data/1.dailycode\345\210\235\351\230\266/3.python/145.exercises/config.json" "b/data/1.dailycode\345\210\235\351\230\266/3.python/145.exercises/config.json" new file mode 100644 index 00000000..ef40ff2f --- /dev/null +++ "b/data/1.dailycode\345\210\235\351\230\266/3.python/145.exercises/config.json" @@ -0,0 +1,10 @@ +{ + "node_id": "dailycode-d4fe0f464d814a09ba53b9dbfbf56e3a", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [], + "export": [ + "solution.json" + ] +} \ No newline at end of file diff --git "a/data/1.dailycode\345\210\235\351\230\266/3.python/145.exercises/solution.json" "b/data/1.dailycode\345\210\235\351\230\266/3.python/145.exercises/solution.json" new file mode 100644 index 00000000..e63e57be --- /dev/null +++ "b/data/1.dailycode\345\210\235\351\230\266/3.python/145.exercises/solution.json" @@ -0,0 +1,7 @@ +{ + "type": "code_options", + "source": "solution.md", + "exercise_id": "54d6ae2161f2477997472d9efe8863c6", + "author": "csdn.net", + "keywords": "栈,树,深度优先搜索,二叉树" +} \ No newline at end of file diff --git "a/data/1.dailycode\345\210\235\351\230\266/3.python/145.exercises/solution.md" "b/data/1.dailycode\345\210\235\351\230\266/3.python/145.exercises/solution.md" new file mode 100644 index 00000000..fb0bfb4c --- /dev/null +++ "b/data/1.dailycode\345\210\235\351\230\266/3.python/145.exercises/solution.md" @@ -0,0 +1,72 @@ +# 二叉树的后序遍历 + +给定一个二叉树,返回它的 后序 遍历。
+ +示例:
+ +输入: [1,null,2,3] + 1 + \ + 2 + / + 3 + +输出: [3,2,1]+ +
进阶: 递归算法很简单,你可以通过迭代算法完成吗?
+ + +## template + +```python +class TreeNode: + def __init__(self, x): + self.val = x + self.left = None + self.right = None + +class Solution(object): + def postorderTraversal(self, root: TreeNode): + + if root is None: + return [] + + stack, output = [], [] + stack.append(root) + while stack: + node = stack.pop() + output.append(node.val) + + if node.left: + stack.append(node.left) + if node.right: + stack.append(node.right) + + return output[::-1] +``` + +## 答案 + +```python + +``` + +## 选项 + +### A + +```python + +``` + +### B + +```python + +``` + +### C + +```python + +``` \ No newline at end of file diff --git "a/data/1.dailycode\345\210\235\351\230\266/3.python/155.exercises/config.json" "b/data/1.dailycode\345\210\235\351\230\266/3.python/155.exercises/config.json" new file mode 100644 index 00000000..3a34f2cf --- /dev/null +++ "b/data/1.dailycode\345\210\235\351\230\266/3.python/155.exercises/config.json" @@ -0,0 +1,10 @@ +{ + "node_id": "dailycode-66d52c7607294afba95f84755f347292", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [], + "export": [ + "solution.json" + ] +} \ No newline at end of file diff --git "a/data/1.dailycode\345\210\235\351\230\266/3.python/155.exercises/solution.json" "b/data/1.dailycode\345\210\235\351\230\266/3.python/155.exercises/solution.json" new file mode 100644 index 00000000..b2a0fc95 --- /dev/null +++ "b/data/1.dailycode\345\210\235\351\230\266/3.python/155.exercises/solution.json" @@ -0,0 +1,7 @@ +{ + "type": "code_options", + "source": "solution.md", + "exercise_id": "4bb5f28525fe48478a71b212cd28e59e", + "author": "csdn.net", + "keywords": "栈,设计" +} \ No newline at end of file diff --git "a/data/1.dailycode\345\210\235\351\230\266/3.python/155.exercises/solution.md" "b/data/1.dailycode\345\210\235\351\230\266/3.python/155.exercises/solution.md" new file mode 100644 index 00000000..113654d6 --- /dev/null +++ "b/data/1.dailycode\345\210\235\351\230\266/3.python/155.exercises/solution.md" @@ -0,0 +1,97 @@ +# 最小栈 + +设计一个支持 push
,pop
,top
操作,并能在常数时间内检索到最小元素的栈。
push(x)
—— 将元素 x 推入栈中。pop()
—— 删除栈顶的元素。top()
—— 获取栈顶元素。getMin()
—— 检索栈中的最小元素。+ +
示例:
+ +输入: +["MinStack","push","push","push","getMin","pop","top","getMin"] +[[],[-2],[0],[-3],[],[],[],[]] + +输出: +[null,null,null,null,-3,null,0,-2] + +解释: +MinStack minStack = new MinStack(); +minStack.push(-2); +minStack.push(0); +minStack.push(-3); +minStack.getMin(); --> 返回 -3. +minStack.pop(); +minStack.top(); --> 返回 0. +minStack.getMin(); --> 返回 -2. ++ +
+ +
提示:
+ +pop
、top
和 getMin
操作总是在 非空栈 上调用。给你两个单链表的头节点 headA
和 headB
,请你找出并返回两个单链表相交的起始节点。如果两个链表没有交点,返回 null
。
图示两个链表在节点 c1
开始相交:
题目数据 保证 整个链式结构中不存在环。
+ +注意,函数返回结果后,链表必须 保持其原始结构 。
+ ++ +
示例 1:
+ + + ++输入:intersectVal = 8, listA = [4,1,8,4,5], listB = [5,0,1,8,4,5], skipA = 2, skipB = 3 +输出:Intersected at '8' +解释:相交节点的值为 8 (注意,如果两个链表相交则不能为 0)。 +从各自的表头开始算起,链表 A 为 [4,1,8,4,5],链表 B 为 [5,0,1,8,4,5]。 +在 A 中,相交节点前有 2 个节点;在 B 中,相交节点前有 3 个节点。 ++ +
示例 2:
+ + + ++输入:intersectVal = 2, listA = [0,9,1,2,4], listB = [3,2,4], skipA = 3, skipB = 1 +输出:Intersected at '2' +解释:相交节点的值为 2 (注意,如果两个链表相交则不能为 0)。 +从各自的表头开始算起,链表 A 为 [0,9,1,2,4],链表 B 为 [3,2,4]。 +在 A 中,相交节点前有 3 个节点;在 B 中,相交节点前有 1 个节点。 ++ +
示例 3:
+ + + ++输入:intersectVal = 0, listA = [2,6,4], listB = [1,5], skipA = 3, skipB = 2 +输出:null +解释:从各自的表头开始算起,链表 A 为 [2,6,4],链表 B 为 [1,5]。 +由于这两个链表不相交,所以 intersectVal 必须为 0,而 skipA 和 skipB 可以是任意值。 +这两个链表不相交,因此返回 null 。 ++ +
+ +
提示:
+ +listA
中节点数目为 m
listB
中节点数目为 n
0 <= m, n <= 3 * 104
1 <= Node.val <= 105
0 <= skipA <= m
0 <= skipB <= n
listA
和 listB
没有交点,intersectVal
为 0
listA
和 listB
有交点,intersectVal == listA[skipA + 1] == listB[skipB + 1]
+ +
进阶:你能否设计一个时间复杂度 O(n)
、仅用 O(1)
内存的解决方案?
给定一个已按照 非递减顺序排列 的整数数组 numbers
,请你从数组中找出两个数满足相加之和等于目标数 target
。
函数应该以长度为 2
的整数数组的形式返回这两个数的下标值。numbers
的下标 从 1 开始计数 ,所以答案数组应当满足 1 <= answer[0] < answer[1] <= numbers.length
。
你可以假设每个输入 只对应唯一的答案 ,而且你 不可以 重复使用相同的元素。
+ + +示例 1:
+ ++输入:numbers = [2,7,11,15], target = 9 +输出:[1,2] +解释:2 与 7 之和等于目标数 9 。因此 index1 = 1, index2 = 2 。 ++ +
示例 2:
+ ++输入:numbers = [2,3,4], target = 6 +输出:[1,3] ++ +
示例 3:
+ ++输入:numbers = [-1,0], target = -1 +输出:[1,2] ++ +
+ +
提示:
+ +2 <= numbers.length <= 3 * 104
-1000 <= numbers[i] <= 1000
numbers
按 非递减顺序 排列-1000 <= target <= 1000
给你一个整数 columnNumber
,返回它在 Excel 表中相对应的列名称。
例如:
+ ++A -> 1 +B -> 2 +C -> 3 +... +Z -> 26 +AA -> 27 +AB -> 28 +... ++ +
+ +
示例 1:
+ ++输入:columnNumber = 1 +输出:"A" ++ +
示例 2:
+ ++输入:columnNumber = 28 +输出:"AB" ++ +
示例 3:
+ ++输入:columnNumber = 701 +输出:"ZY" ++ +
示例 4:
+ ++输入:columnNumber = 2147483647 +输出:"FXSHRXW" ++ +
+ +
提示:
+ +1 <= columnNumber <= 231 - 1
给定一个大小为 n 的数组,找到其中的多数元素。多数元素是指在数组中出现次数 大于 ⌊ n/2 ⌋
的元素。
你可以假设数组是非空的,并且给定的数组总是存在多数元素。
+ ++ +
示例 1:
+ ++输入:[3,2,3] +输出:3+ +
示例 2:
+ ++输入:[2,2,1,1,1,2,2] +输出:2 ++ +
+ +
进阶:
+ +给你一个字符串 columnTitle
,表示 Excel 表格中的列名称。返回该列名称对应的列序号。
+ +
例如,
+ ++ A -> 1 + B -> 2 + C -> 3 + ... + Z -> 26 + AA -> 27 + AB -> 28 + ... ++ +
+ +
示例 1:
+ ++输入: columnTitle = "A" +输出: 1 ++ +
示例 2:
+ ++输入: columnTitle = "AB" +输出: 28 ++ +
示例 3:
+ ++输入: columnTitle = "ZY" +输出: 701+ +
示例 4:
+ ++输入: columnTitle = "FXSHRXW" +输出: 2147483647 ++ +
+ +
提示:
+ +1 <= columnTitle.length <= 7
columnTitle
仅由大写英文组成columnTitle
在范围 ["A", "FXSHRXW"]
内给定一个整数 n
,返回 n!
结果中尾随零的数量。
提示 n! = n * (n - 1) * (n - 2) * ... * 3 * 2 * 1
+ +
示例 1:
+ ++输入:n = 3 +输出:0 +解释:3! = 6 ,不含尾随 0 ++ +
示例 2:
+ ++输入:n = 5 +输出:1 +解释:5! = 120 ,有一个尾随 0 ++ +
示例 3:
+ ++输入:n = 0 +输出:0 ++ +
+ +
提示:
+ +0 <= n <= 104
+ +
进阶:你可以设计并实现对数时间复杂度的算法来解决此问题吗?
+ + +## template + +```python +class Solution: + def trailingZeroes(self, n: int) -> int: + zero_count = 0 + current_multiple = 5 + while n >= current_multiple: + zero_count += n // current_multiple + current_multiple *= 5 + return zero_count + +``` + +## 答案 + +```python + +``` + +## 选项 + +### A + +```python + +``` + +### B + +```python + +``` + +### C + +```python + +``` \ No newline at end of file diff --git "a/data/1.dailycode\345\210\235\351\230\266/3.python/190.exercises/config.json" "b/data/1.dailycode\345\210\235\351\230\266/3.python/190.exercises/config.json" new file mode 100644 index 00000000..8a76d631 --- /dev/null +++ "b/data/1.dailycode\345\210\235\351\230\266/3.python/190.exercises/config.json" @@ -0,0 +1,10 @@ +{ + "node_id": "dailycode-ba1e4e9897d64eaf9ac066a03437b62f", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [], + "export": [ + "solution.json" + ] +} \ No newline at end of file diff --git "a/data/1.dailycode\345\210\235\351\230\266/3.python/190.exercises/solution.json" "b/data/1.dailycode\345\210\235\351\230\266/3.python/190.exercises/solution.json" new file mode 100644 index 00000000..decb2ff5 --- /dev/null +++ "b/data/1.dailycode\345\210\235\351\230\266/3.python/190.exercises/solution.json" @@ -0,0 +1,7 @@ +{ + "type": "code_options", + "source": "solution.md", + "exercise_id": "1ba368a03960439599d6d1b5e6867284", + "author": "csdn.net", + "keywords": "位运算,分治" +} \ No newline at end of file diff --git "a/data/1.dailycode\345\210\235\351\230\266/3.python/190.exercises/solution.md" "b/data/1.dailycode\345\210\235\351\230\266/3.python/190.exercises/solution.md" new file mode 100644 index 00000000..bdda5344 --- /dev/null +++ "b/data/1.dailycode\345\210\235\351\230\266/3.python/190.exercises/solution.md" @@ -0,0 +1,82 @@ +# 颠倒二进制位 + +颠倒给定的 32 位无符号整数的二进制位。
+ +提示:
+ +-3
,输出表示有符号整数 -1073741825
。+ +
示例 1:
+ ++输入:n = 00000010100101000001111010011100 +输出:964176192 (00111001011110000010100101000000) +解释:输入的二进制串 00000010100101000001111010011100 表示无符号整数 43261596, + 因此返回 964176192,其二进制表示形式为 00111001011110000010100101000000。+ +
示例 2:
+ ++输入:n = 11111111111111111111111111111101 +输出:3221225471 (10111111111111111111111111111111) +解释:输入的二进制串 11111111111111111111111111111101 表示无符号整数 4294967293, + 因此返回 3221225471 其二进制表示形式为 10111111111111111111111111111111 。+ +
+ +
提示:
+ +32
的二进制字符串+ +
进阶: 如果多次调用这个函数,你将如何优化你的算法?
+ + +## template + +```python +class Solution: + def reverseBits(self, n: int) -> int: + j = 0 + y = bin(n)[2::] + if len(y) != 32: + j = 32 - len(y) + m = y[::-1] + m = m + "0" * j + return int(m, 2) + +``` + +## 答案 + +```python + +``` + +## 选项 + +### A + +```python + +``` + +### B + +```python + +``` + +### C + +```python + +``` \ No newline at end of file diff --git "a/data/1.dailycode\345\210\235\351\230\266/3.python/191.exercises/config.json" "b/data/1.dailycode\345\210\235\351\230\266/3.python/191.exercises/config.json" new file mode 100644 index 00000000..c66d46fc --- /dev/null +++ "b/data/1.dailycode\345\210\235\351\230\266/3.python/191.exercises/config.json" @@ -0,0 +1,10 @@ +{ + "node_id": "dailycode-e46a5de28b3b481ca0a2f72f087542bf", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [], + "export": [ + "solution.json" + ] +} \ No newline at end of file diff --git "a/data_source/exercises/\344\270\255\347\255\211/python/192.exercises/solution.json" "b/data/1.dailycode\345\210\235\351\230\266/3.python/191.exercises/solution.json" similarity index 66% rename from "data_source/exercises/\344\270\255\347\255\211/python/192.exercises/solution.json" rename to "data/1.dailycode\345\210\235\351\230\266/3.python/191.exercises/solution.json" index cf41a146..45482188 100644 --- "a/data_source/exercises/\344\270\255\347\255\211/python/192.exercises/solution.json" +++ "b/data/1.dailycode\345\210\235\351\230\266/3.python/191.exercises/solution.json" @@ -1,7 +1,7 @@ { "type": "code_options", "source": "solution.md", - "exercise_id": "9ac6dd56154b4494a3cf9d08fab84d02", + "exercise_id": "430b7b13abf747cc86a8ceb4b3db33d8", "author": "csdn.net", "keywords": "位运算" } \ No newline at end of file diff --git "a/data/1.dailycode\345\210\235\351\230\266/3.python/191.exercises/solution.md" "b/data/1.dailycode\345\210\235\351\230\266/3.python/191.exercises/solution.md" new file mode 100644 index 00000000..60507a63 --- /dev/null +++ "b/data/1.dailycode\345\210\235\351\230\266/3.python/191.exercises/solution.md" @@ -0,0 +1,107 @@ +# 位1的个数 + +编写一个函数,输入是一个无符号整数(以二进制串的形式),返回其二进制表达式中数字位数为 '1' 的个数(也被称为汉明重量)。
+ ++ +
提示:
+ +-3
。+ +
示例 1:
+ +
+输入:00000000000000000000000000001011
+输出:3
+解释:输入的二进制串 00000000000000000000000000001011 中,共有三位为 '1'。
+
+
+示例 2:
+ ++输入:00000000000000000000000010000000 +输出:1 +解释:输入的二进制串 00000000000000000000000010000000 中,共有一位为 '1'。 ++ +
示例 3:
+ ++输入:11111111111111111111111111111101 +输出:31 +解释:输入的二进制串 11111111111111111111111111111101 中,共有 31 位为 '1'。+ +
+ +
提示:
+ +32
的 二进制串 。+ +
进阶:
+ +编写一个算法来判断一个数 n
是不是快乐数。
「快乐数」定义为:
+ +如果 n
是快乐数就返回 true
;不是,则返回 false
。
+ +
示例 1:
+ ++输入:19 +输出:true +解释: +12 + 92 = 82 +82 + 22 = 68 +62 + 82 = 100 +12 + 02 + 02 = 1 ++ +
示例 2:
+ ++输入:n = 2 +输出:false ++ +
+ +
提示:
+ +1 <= n <= 231 - 1
head
和一个整数 val
,请你删除链表中所有满足 Node.val == val
的节点,并返回 新的头节点 。
++ +
示例 1:
+ ++输入:head = [1,2,6,3,4,5,6], val = 6 +输出:[1,2,3,4,5] ++ +
示例 2:
+ ++输入:head = [], val = 1 +输出:[] ++ +
示例 3:
+ ++输入:head = [7,7,7,7], val = 7 +输出:[] ++ +
+ +
提示:
+ +[0, 104]
内1 <= Node.val <= 50
0 <= val <= 50
统计所有小于非负整数 n
的质数的数量。
+ +
示例 1:
+ +输入:n = 10 +输出:4 +解释:小于 10 的质数一共有 4 个, 它们是 2, 3, 5, 7 。 ++ +
示例 2:
+ +输入:n = 0 +输出:0 ++ +
示例 3:
+ +输入:n = 1 +输出:0 ++ +
+ +
提示:
+ +0 <= n <= 5 * 106
给定两个字符串 s 和 t,判断它们是否是同构的。
+ +如果 s 中的字符可以按某种映射关系替换得到 t ,那么这两个字符串是同构的。
+ +每个出现的字符都应当映射到另一个字符,同时不改变字符的顺序。不同字符不能映射到同一个字符上,相同字符只能映射到同一个字符上,字符可以映射到自己本身。
+ ++ +
示例 1:
+ ++输入:s =+ +"egg",
t ="add"
+输出:true +
示例 2:
+ ++输入:s =+ +"foo",
t ="bar"
+输出:false
示例 3:
+ ++输入:s =+ +"paper",
t ="title"
+输出:true
+ +
提示:
+ +head
,请你反转链表,并返回反转后的链表。
++ +
示例 1:
+ ++输入:head = [1,2,3,4,5] +输出:[5,4,3,2,1] ++ +
示例 2:
+ ++输入:head = [1,2] +输出:[2,1] ++ +
示例 3:
+ ++输入:head = [] +输出:[] ++ +
+ +
提示:
+ +[0, 5000]
-5000 <= Node.val <= 5000
+ +
进阶:链表可以选用迭代或递归方式完成反转。你能否用两种方法解决这道题?
+给定一个整数数组,判断是否存在重复元素。
+ +如果存在一值在数组中出现至少两次,函数返回 true
。如果数组中每个元素都不相同,则返回 false
。
+ +
示例 1:
+ ++输入: [1,2,3,1] +输出: true+ +
示例 2:
+ ++输入: [1,2,3,4] +输出: false+ +
示例 3:
+ ++输入: [1,1,1,3,3,4,3,2,4,2] +输出: true+ + +## template + +```python +class Solution: + def containsDuplicate(self, nums: List[int]) -> bool: + + nums.sort() + count = 0 + while count < len(nums) - 1: + if nums[count] == nums[count + 1]: + return True + count += 1 + return False + +``` + +## 答案 + +```python + +``` + +## 选项 + +### A + +```python + +``` + +### B + +```python + +``` + +### C + +```python + +``` \ No newline at end of file diff --git "a/data/1.dailycode\345\210\235\351\230\266/3.python/219.exercises/config.json" "b/data/1.dailycode\345\210\235\351\230\266/3.python/219.exercises/config.json" new file mode 100644 index 00000000..8deade39 --- /dev/null +++ "b/data/1.dailycode\345\210\235\351\230\266/3.python/219.exercises/config.json" @@ -0,0 +1,10 @@ +{ + "node_id": "dailycode-c577cd4335a846a5bae08b419ecf7236", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [], + "export": [ + "solution.json" + ] +} \ No newline at end of file diff --git "a/data/1.dailycode\345\210\235\351\230\266/3.python/219.exercises/solution.json" "b/data/1.dailycode\345\210\235\351\230\266/3.python/219.exercises/solution.json" new file mode 100644 index 00000000..353c0f57 --- /dev/null +++ "b/data/1.dailycode\345\210\235\351\230\266/3.python/219.exercises/solution.json" @@ -0,0 +1,7 @@ +{ + "type": "code_options", + "source": "solution.md", + "exercise_id": "ba81057039ca4027a1dec611797bbdc6", + "author": "csdn.net", + "keywords": "数组,哈希表,滑动窗口" +} \ No newline at end of file diff --git "a/data/1.dailycode\345\210\235\351\230\266/3.python/219.exercises/solution.md" "b/data/1.dailycode\345\210\235\351\230\266/3.python/219.exercises/solution.md" new file mode 100644 index 00000000..b106c22c --- /dev/null +++ "b/data/1.dailycode\345\210\235\351\230\266/3.python/219.exercises/solution.md" @@ -0,0 +1,78 @@ +# 存在重复元素 II + +
给定一个整数数组和一个整数 k,判断数组中是否存在两个不同的索引 i 和 j,使得 nums [i] = nums [j],并且 i 和 j 的差的 绝对值 至多为 k。
+ ++ +
示例 1:
+ +输入: nums = [1,2,3,1], k = 3 +输出: true+ +
示例 2:
+ +输入: nums = [1,0,1,1], k = 1 +输出: true+ +
示例 3:
+ +输入: nums = [1,2,3,1,2,3], k = 2 +输出: false+ + +## template + +```python +class Solution: + def containsNearbyDuplicate(self, nums, k): + """ + :type nums: List[int] + :type k: int + :rtype: bool + """ + + if len(list(set(nums))) == len(nums): + return False + left = 0 + right = left + k + if k >= len(nums): + return len(list(set(nums))) < len(nums) + while right < len(nums): + while left < right: + if nums[left] == nums[right]: + return True + else: + right -= 1 + left += 1 + right = left + k + if len(list(set(nums[left:]))) < len(nums[left:]): + return True + return False + +``` + +## 答案 + +```python + +``` + +## 选项 + +### A + +```python + +``` + +### B + +```python + +``` + +### C + +```python + +``` \ No newline at end of file diff --git "a/data/1.dailycode\345\210\235\351\230\266/3.python/225.exercises/config.json" "b/data/1.dailycode\345\210\235\351\230\266/3.python/225.exercises/config.json" new file mode 100644 index 00000000..6ff28a62 --- /dev/null +++ "b/data/1.dailycode\345\210\235\351\230\266/3.python/225.exercises/config.json" @@ -0,0 +1,10 @@ +{ + "node_id": "dailycode-cffa52e97c224fdf8530778290a05c2d", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [], + "export": [ + "solution.json" + ] +} \ No newline at end of file diff --git "a/data/1.dailycode\345\210\235\351\230\266/3.python/225.exercises/solution.json" "b/data/1.dailycode\345\210\235\351\230\266/3.python/225.exercises/solution.json" new file mode 100644 index 00000000..4e316c3f --- /dev/null +++ "b/data/1.dailycode\345\210\235\351\230\266/3.python/225.exercises/solution.json" @@ -0,0 +1,7 @@ +{ + "type": "code_options", + "source": "solution.md", + "exercise_id": "ef25569152e840bba97c52891b63d50c", + "author": "csdn.net", + "keywords": "栈,设计,队列" +} \ No newline at end of file diff --git "a/data/1.dailycode\345\210\235\351\230\266/3.python/225.exercises/solution.md" "b/data/1.dailycode\345\210\235\351\230\266/3.python/225.exercises/solution.md" new file mode 100644 index 00000000..c127de84 --- /dev/null +++ "b/data/1.dailycode\345\210\235\351\230\266/3.python/225.exercises/solution.md" @@ -0,0 +1,133 @@ +# 用队列实现栈 + +
请你仅使用两个队列实现一个后入先出(LIFO)的栈,并支持普通栈的全部四种操作(push
、top
、pop
和 empty
)。
实现 MyStack
类:
void push(int x)
将元素 x 压入栈顶。int pop()
移除并返回栈顶元素。int top()
返回栈顶元素。boolean empty()
如果栈是空的,返回 true
;否则,返回 false
。+ +
注意:
+ +push to back
、peek/pop from front
、size
和 is empty
这些操作。+ +
示例:
+ ++输入: +["MyStack", "push", "push", "top", "pop", "empty"] +[[], [1], [2], [], [], []] +输出: +[null, null, null, 2, 2, false] + +解释: +MyStack myStack = new MyStack(); +myStack.push(1); +myStack.push(2); +myStack.top(); // 返回 2 +myStack.pop(); // 返回 2 +myStack.empty(); // 返回 False ++ +
+ +
提示:
+ +1 <= x <= 9
100
次 push
、pop
、top
和 empty
pop
和 top
都保证栈不为空+ +
进阶:你能否实现每种操作的均摊时间复杂度为 O(1)
的栈?换句话说,执行 n
个操作的总时间复杂度 O(n)
,尽管其中某个操作可能需要比其他操作更长的时间。你可以使用两个以上的队列。
翻转一棵二叉树。
+ +示例:
+ +输入:
+ +4 + / \ + 2 7 + / \ / \ +1 3 6 9+ +
输出:
+ +4 + / \ + 7 2 + / \ / \ +9 6 3 1+ +
备注:
+这个问题是受到 Max Howell 的 原问题 启发的 :
谷歌:我们90%的工程师使用您编写的软件(Homebrew),但是您却无法在面试时在白板上写出翻转二叉树这道题,这太糟糕了。+ + +## template + +```python +class TreeNode: + def __init__(self, x): + self.val = x + self.left = None + self.right = None + + +class Solution(object): + def invertTree(self, root): + """ + :type root: TreeNode + :rtype: TreeNode + """ + + if not root: + return None + root.left, root.right = root.right, root.left + + self.invertTree(root.left) + self.invertTree(root.right) + + return root +``` + +## 答案 + +```python + +``` + +## 选项 + +### A + +```python + +``` + +### B + +```python + +``` + +### C + +```python + +``` \ No newline at end of file diff --git "a/data/1.dailycode\345\210\235\351\230\266/3.python/228.exercises/config.json" "b/data/1.dailycode\345\210\235\351\230\266/3.python/228.exercises/config.json" new file mode 100644 index 00000000..c44baa40 --- /dev/null +++ "b/data/1.dailycode\345\210\235\351\230\266/3.python/228.exercises/config.json" @@ -0,0 +1,10 @@ +{ + "node_id": "dailycode-fddac17d19ec4980b2c56a61a6606757", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [], + "export": [ + "solution.json" + ] +} \ No newline at end of file diff --git "a/data_source/exercises/\347\256\200\345\215\225/python/163.exercises/solution.json" "b/data/1.dailycode\345\210\235\351\230\266/3.python/228.exercises/solution.json" similarity index 65% rename from "data_source/exercises/\347\256\200\345\215\225/python/163.exercises/solution.json" rename to "data/1.dailycode\345\210\235\351\230\266/3.python/228.exercises/solution.json" index 2f369bd6..14cfd307 100644 --- "a/data_source/exercises/\347\256\200\345\215\225/python/163.exercises/solution.json" +++ "b/data/1.dailycode\345\210\235\351\230\266/3.python/228.exercises/solution.json" @@ -1,7 +1,7 @@ { "type": "code_options", "source": "solution.md", - "exercise_id": "9709c270ce6e4255b49fa2f3a89a8f1b", + "exercise_id": "1846ac34e8624af7b4080f3b6af1b5aa", "author": "csdn.net", "keywords": "数组" } \ No newline at end of file diff --git "a/data/1.dailycode\345\210\235\351\230\266/3.python/228.exercises/solution.md" "b/data/1.dailycode\345\210\235\351\230\266/3.python/228.exercises/solution.md" new file mode 100644 index 00000000..476f1717 --- /dev/null +++ "b/data/1.dailycode\345\210\235\351\230\266/3.python/228.exercises/solution.md" @@ -0,0 +1,126 @@ +# 汇总区间 + +
给定一个无重复元素的有序整数数组 nums
。
返回 恰好覆盖数组中所有数字 的 最小有序 区间范围列表。也就是说,nums
的每个元素都恰好被某个区间范围所覆盖,并且不存在属于某个范围但不属于 nums
的数字 x
。
列表中的每个区间范围 [a,b]
应该按如下格式输出:
"a->b"
,如果 a != b
"a"
,如果 a == b
+ +
示例 1:
+ ++输入:nums = [0,1,2,4,5,7] +输出:["0->2","4->5","7"] +解释:区间范围是: +[0,2] --> "0->2" +[4,5] --> "4->5" +[7,7] --> "7" ++ +
示例 2:
+ ++输入:nums = [0,2,3,4,6,8,9] +输出:["0","2->4","6","8->9"] +解释:区间范围是: +[0,0] --> "0" +[2,4] --> "2->4" +[6,6] --> "6" +[8,9] --> "8->9" ++ +
示例 3:
+ ++输入:nums = [] +输出:[] ++ +
示例 4:
+ ++输入:nums = [-1] +输出:["-1"] ++ +
示例 5:
+ ++输入:nums = [0] +输出:["0"] ++ +
+ +
提示:
+ +0 <= nums.length <= 20
-231 <= nums[i] <= 231 - 1
nums
中的所有值都 互不相同nums
按升序排列给你一个整数 n
,请你判断该整数是否是 2 的幂次方。如果是,返回 true
;否则,返回 false
。
如果存在一个整数 x
使得 n == 2x
,则认为 n
是 2 的幂次方。
+ +
示例 1:
+ ++输入:n = 1 +输出:true +解释:20 = 1 ++ +
示例 2:
+ ++输入:n = 16 +输出:true +解释:24 = 16 ++ +
示例 3:
+ ++输入:n = 3 +输出:false ++ +
示例 4:
+ ++输入:n = 4 +输出:true ++ +
示例 5:
+ ++输入:n = 5 +输出:false ++ +
+ +
提示:
+ +-231 <= n <= 231 - 1
+ +
进阶:你能够不使用循环/递归解决此问题吗?
+ + +## template + +```python + +class Solution: + def isPowerOfTwo(self, n): + z = bin(n)[2:] + if z[0] != "1": + return False + for item in z[1:]: + if item != "0": + return False + return True +``` + +## 答案 + +```python + +``` + +## 选项 + +### A + +```python + +``` + +### B + +```python + +``` + +### C + +```python + +``` \ No newline at end of file diff --git "a/data/1.dailycode\345\210\235\351\230\266/3.python/232.exercises/config.json" "b/data/1.dailycode\345\210\235\351\230\266/3.python/232.exercises/config.json" new file mode 100644 index 00000000..45575244 --- /dev/null +++ "b/data/1.dailycode\345\210\235\351\230\266/3.python/232.exercises/config.json" @@ -0,0 +1,10 @@ +{ + "node_id": "dailycode-cb7541d2e206474e8310b24bbcaa603a", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [], + "export": [ + "solution.json" + ] +} \ No newline at end of file diff --git "a/data/1.dailycode\345\210\235\351\230\266/3.python/232.exercises/solution.json" "b/data/1.dailycode\345\210\235\351\230\266/3.python/232.exercises/solution.json" new file mode 100644 index 00000000..747cbedc --- /dev/null +++ "b/data/1.dailycode\345\210\235\351\230\266/3.python/232.exercises/solution.json" @@ -0,0 +1,7 @@ +{ + "type": "code_options", + "source": "solution.md", + "exercise_id": "6ce261204e1f4348a5f2ad5e526bd238", + "author": "csdn.net", + "keywords": "栈,设计,队列" +} \ No newline at end of file diff --git "a/data/1.dailycode\345\210\235\351\230\266/3.python/232.exercises/solution.md" "b/data/1.dailycode\345\210\235\351\230\266/3.python/232.exercises/solution.md" new file mode 100644 index 00000000..5f84610e --- /dev/null +++ "b/data/1.dailycode\345\210\235\351\230\266/3.python/232.exercises/solution.md" @@ -0,0 +1,148 @@ +# 用栈实现队列 + +请你仅使用两个栈实现先入先出队列。队列应当支持一般队列支持的所有操作(push
、pop
、peek
、empty
):
实现 MyQueue
类:
void push(int x)
将元素 x 推到队列的末尾int pop()
从队列的开头移除并返回元素int peek()
返回队列开头的元素boolean empty()
如果队列为空,返回 true
;否则,返回 false
+ +
说明:
+ +push to top
, peek/pop from top
, size
, 和 is empty
操作是合法的。+ +
进阶:
+ +O(1)
的队列?换句话说,执行 n
个操作的总时间复杂度为 O(n)
,即使其中一个操作可能花费较长时间。+ +
示例:
+ ++输入: +["MyQueue", "push", "push", "peek", "pop", "empty"] +[[], [1], [2], [], [], []] +输出: +[null, null, null, 1, 1, false] + +解释: +MyQueue myQueue = new MyQueue(); +myQueue.push(1); // queue is: [1] +myQueue.push(2); // queue is: [1, 2] (leftmost is front of the queue) +myQueue.peek(); // return 1 +myQueue.pop(); // return 1, queue is [2] +myQueue.empty(); // return false ++ +
+ +
提示:
+ +1 <= x <= 9
100
次 push
、pop
、peek
和 empty
pop
或者 peek
操作)给你一个单链表的头节点 head
,请你判断该链表是否为回文链表。如果是,返回 true
;否则,返回 false
。
+ +
示例 1:
+ ++输入:head = [1,2,2,1] +输出:true ++ +
示例 2:
+ ++输入:head = [1,2] +输出:false ++ +
+ +
提示:
+ +[1, 105]
内0 <= Node.val <= 9
+ +
进阶:你能否用 O(n)
时间复杂度和 O(1)
空间复杂度解决此题?
给你一个二叉树,请你返回其按 层序遍历 得到的节点值。 (即逐层地,从左到右访问所有节点)。
+ ++ +
示例:
+二叉树:[3,9,20,null,null,15,7]
,
+ 3 + / \ + 9 20 + / \ + 15 7 ++ +
返回其层序遍历结果:
+ ++[ + [3], + [9,20], + [15,7] +] ++ + +## template + +```python +class TreeNode: + def __init__(self, x): + self.val = x + self.left = None + self.right = None + +class Solution(object): + def levelOrder(self, root): + """ + :type root: TreeNode + :rtype: List[List[int]] + """ + if not root: + return [] + + queue, res = [root], [] + while queue: + size = len(queue) + temp = [] + for i in range(size): + data = queue.pop(0) + temp.append(data.val) + if data.left: + queue.append(data.left) + if data.right: + queue.append(data.right) + res.append(temp) + return res + +``` + +## 答案 + +```python + +``` + +## 选项 + +### A + +```python + +``` + +### B + +```python + +``` + +### C + +```python + +``` \ No newline at end of file diff --git "a/data/2.dailycode\344\270\255\351\230\266/3.python/103.exercises/config.json" "b/data/2.dailycode\344\270\255\351\230\266/3.python/103.exercises/config.json" new file mode 100644 index 00000000..cd2a80b3 --- /dev/null +++ "b/data/2.dailycode\344\270\255\351\230\266/3.python/103.exercises/config.json" @@ -0,0 +1,10 @@ +{ + "node_id": "dailycode-076557859b544f95a2873bfb35e2c94c", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [], + "export": [ + "solution.json" + ] +} \ No newline at end of file diff --git "a/data/2.dailycode\344\270\255\351\230\266/3.python/103.exercises/solution.json" "b/data/2.dailycode\344\270\255\351\230\266/3.python/103.exercises/solution.json" new file mode 100644 index 00000000..e8d5e422 --- /dev/null +++ "b/data/2.dailycode\344\270\255\351\230\266/3.python/103.exercises/solution.json" @@ -0,0 +1,7 @@ +{ + "type": "code_options", + "source": "solution.md", + "exercise_id": "a556fe7a24864dd7ba234c963c36948f", + "author": "csdn.net", + "keywords": "树,广度优先搜索,二叉树" +} \ No newline at end of file diff --git "a/data/2.dailycode\344\270\255\351\230\266/3.python/103.exercises/solution.md" "b/data/2.dailycode\344\270\255\351\230\266/3.python/103.exercises/solution.md" new file mode 100644 index 00000000..77170350 --- /dev/null +++ "b/data/2.dailycode\344\270\255\351\230\266/3.python/103.exercises/solution.md" @@ -0,0 +1,91 @@ +# 二叉树的锯齿形层序遍历 + +
给定一个二叉树,返回其节点值的锯齿形层序遍历。(即先从左往右,再从右往左进行下一层遍历,以此类推,层与层之间交替进行)。
+ +例如:
+给定二叉树 [3,9,20,null,null,15,7]
,
+ 3 + / \ + 9 20 + / \ + 15 7 ++ +
返回锯齿形层序遍历如下:
+ ++[ + [3], + [20,9], + [15,7] +] ++ + +## template + +```python +class TreeNode: + def __init__(self, x): + self.val = x + self.left = None + self.right = None + +class Solution: + def zigzagLevelOrder(self, root: TreeNode) -> List[List[int]]: + import collections + + if not root: + return [] + + res, q = [], collections.deque() + flag = False + q.append(root) + + while q: + temp = [] + flag = not flag + for _ in range(len(q)): + node = q.popleft() + + if flag: + temp.append(node.val) + + else: + temp.insert(0, node.val) + if node.left: + q.append(node.left) + if node.right: + q.append(node.right) + res.append(temp) + + return res +``` + +## 答案 + +```python + +``` + +## 选项 + +### A + +```python + +``` + +### B + +```python + +``` + +### C + +```python + +``` \ No newline at end of file diff --git "a/data/2.dailycode\344\270\255\351\230\266/3.python/105.exercises/config.json" "b/data/2.dailycode\344\270\255\351\230\266/3.python/105.exercises/config.json" new file mode 100644 index 00000000..a1783501 --- /dev/null +++ "b/data/2.dailycode\344\270\255\351\230\266/3.python/105.exercises/config.json" @@ -0,0 +1,10 @@ +{ + "node_id": "dailycode-ccd566240ba349dd8efd97bf8b840767", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [], + "export": [ + "solution.json" + ] +} \ No newline at end of file diff --git "a/data/2.dailycode\344\270\255\351\230\266/3.python/105.exercises/solution.json" "b/data/2.dailycode\344\270\255\351\230\266/3.python/105.exercises/solution.json" new file mode 100644 index 00000000..7b3364e5 --- /dev/null +++ "b/data/2.dailycode\344\270\255\351\230\266/3.python/105.exercises/solution.json" @@ -0,0 +1,7 @@ +{ + "type": "code_options", + "source": "solution.md", + "exercise_id": "6f8b176b8b2c40be9b35e4b7d7b02e5e", + "author": "csdn.net", + "keywords": "树,数组,哈希表,分治,二叉树" +} \ No newline at end of file diff --git "a/data/2.dailycode\344\270\255\351\230\266/3.python/105.exercises/solution.md" "b/data/2.dailycode\344\270\255\351\230\266/3.python/105.exercises/solution.md" new file mode 100644 index 00000000..202c59db --- /dev/null +++ "b/data/2.dailycode\344\270\255\351\230\266/3.python/105.exercises/solution.md" @@ -0,0 +1,80 @@ +# 从前序与中序遍历序列构造二叉树 + +
给定一棵树的前序遍历 preorder
与中序遍历 inorder
。请构造二叉树并返回其根节点。
+ +
示例 1:
+ ++Input: preorder = [3,9,20,15,7], inorder = [9,3,15,20,7] +Output: [3,9,20,null,null,15,7] ++ +
示例 2:
+ ++Input: preorder = [-1], inorder = [-1] +Output: [-1] ++ +
+ +
提示:
+ +1 <= preorder.length <= 3000
inorder.length == preorder.length
-3000 <= preorder[i], inorder[i] <= 3000
preorder
和 inorder
均无重复元素inorder
均出现在 preorder
preorder
保证为二叉树的前序遍历序列inorder
保证为二叉树的中序遍历序列根据一棵树的中序遍历与后序遍历构造二叉树。
+ +注意:
+你可以假设树中没有重复的元素。
例如,给出
+ +中序遍历 inorder = [9,3,15,20,7] +后序遍历 postorder = [9,15,7,20,3]+ +
返回如下的二叉树:
+ +3 + / \ + 9 20 + / \ + 15 7 ++ + +## template + +```python + +class Solution: + def buildTree(self, inorder: List[int], postorder: List[int]) -> TreeNode: + def build_tree(in_left, in_right, post_left, post_right): + if in_left > in_right: + return + + post_root = post_right + + root = TreeNode(postorder[post_root]) + + in_root = inorder_map[root.val] + + size_of_left = in_root - in_left + + root.left = build_tree( + in_left, in_root - 1, post_left, post_left + size_of_left - 1 + ) + + root.right = build_tree( + in_root + 1, in_right, post_left + size_of_left, post_root - 1 + ) + + return root + + size = len(inorder) + + inorder_map = {} + + for i in range(size): + inorder_map[inorder[i]] = i + + return build_tree(0, size - 1, 0, size - 1) + + +``` + +## 答案 + +```python + +``` + +## 选项 + +### A + +```python + +``` + +### B + +```python + +``` + +### C + +```python + +``` \ No newline at end of file diff --git "a/data/2.dailycode\344\270\255\351\230\266/3.python/107.exercises/config.json" "b/data/2.dailycode\344\270\255\351\230\266/3.python/107.exercises/config.json" new file mode 100644 index 00000000..cd0dce85 --- /dev/null +++ "b/data/2.dailycode\344\270\255\351\230\266/3.python/107.exercises/config.json" @@ -0,0 +1,10 @@ +{ + "node_id": "dailycode-23bb016c10994736ad14a29a819eba08", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [], + "export": [ + "solution.json" + ] +} \ No newline at end of file diff --git "a/data/2.dailycode\344\270\255\351\230\266/3.python/107.exercises/solution.json" "b/data/2.dailycode\344\270\255\351\230\266/3.python/107.exercises/solution.json" new file mode 100644 index 00000000..3a53826b --- /dev/null +++ "b/data/2.dailycode\344\270\255\351\230\266/3.python/107.exercises/solution.json" @@ -0,0 +1,7 @@ +{ + "type": "code_options", + "source": "solution.md", + "exercise_id": "6a4098c9e916419baa1969bad6b58b87", + "author": "csdn.net", + "keywords": "树,广度优先搜索,二叉树" +} \ No newline at end of file diff --git "a/data/2.dailycode\344\270\255\351\230\266/3.python/107.exercises/solution.md" "b/data/2.dailycode\344\270\255\351\230\266/3.python/107.exercises/solution.md" new file mode 100644 index 00000000..e185a4da --- /dev/null +++ "b/data/2.dailycode\344\270\255\351\230\266/3.python/107.exercises/solution.md" @@ -0,0 +1,75 @@ +# 二叉树的层序遍历 II + +
给定一个二叉树,返回其节点值自底向上的层序遍历。 (即按从叶子节点所在层到根节点所在的层,逐层从左向右遍历)
+ +例如:
+给定二叉树 [3,9,20,null,null,15,7]
,
+ 3 + / \ + 9 20 + / \ + 15 7 ++ +
返回其自底向上的层序遍历为:
+ ++[ + [15,7], + [9,20], + [3] +] ++ + +## template + +```python + +class Solution(object): + res = dict() + + def forwardSearch(self, root, depth): + if root != None: + if depth not in self.res.keys(): + self.res[depth] = [] + self.res[depth].append(root.val) + self.forwardSearch(root.left, depth + 1) + self.forwardSearch(root.right, depth + 1) + + def levelOrderBottom(self, root): + self.forwardSearch(root, 1) + result = [] + self.dic = dict() + for i in self.res.keys(): + result.append(self.res[i]) + return result[::-1] +``` + +## 答案 + +```python + +``` + +## 选项 + +### A + +```python + +``` + +### B + +```python + +``` + +### C + +```python + +``` \ No newline at end of file diff --git "a/data/2.dailycode\344\270\255\351\230\266/3.python/109.exercises/config.json" "b/data/2.dailycode\344\270\255\351\230\266/3.python/109.exercises/config.json" new file mode 100644 index 00000000..edfd8a68 --- /dev/null +++ "b/data/2.dailycode\344\270\255\351\230\266/3.python/109.exercises/config.json" @@ -0,0 +1,10 @@ +{ + "node_id": "dailycode-8b5ed7c1f80f476e91cb817707d93420", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [], + "export": [ + "solution.json" + ] +} \ No newline at end of file diff --git "a/data/2.dailycode\344\270\255\351\230\266/3.python/109.exercises/solution.json" "b/data/2.dailycode\344\270\255\351\230\266/3.python/109.exercises/solution.json" new file mode 100644 index 00000000..3b0b8e8c --- /dev/null +++ "b/data/2.dailycode\344\270\255\351\230\266/3.python/109.exercises/solution.json" @@ -0,0 +1,7 @@ +{ + "type": "code_options", + "source": "solution.md", + "exercise_id": "f5dd9b0f00a740e08275f50e60a4c7f6", + "author": "csdn.net", + "keywords": "树,二叉搜索树,链表,分治,二叉树" +} \ No newline at end of file diff --git "a/data/2.dailycode\344\270\255\351\230\266/3.python/109.exercises/solution.md" "b/data/2.dailycode\344\270\255\351\230\266/3.python/109.exercises/solution.md" new file mode 100644 index 00000000..29ee3ae3 --- /dev/null +++ "b/data/2.dailycode\344\270\255\351\230\266/3.python/109.exercises/solution.md" @@ -0,0 +1,89 @@ +# 有序链表转换二叉搜索树 + +
给定一个单链表,其中的元素按升序排序,将其转换为高度平衡的二叉搜索树。
+ +本题中,一个高度平衡二叉树是指一个二叉树每个节点 的左右两个子树的高度差的绝对值不超过 1。
+ +示例:
+ +给定的有序链表: [-10, -3, 0, 5, 9], + +一个可能的答案是:[0, -3, 9, -10, null, 5], 它可以表示下面这个高度平衡二叉搜索树: + + 0 + / \ + -3 9 + / / + -10 5 ++ + +## template + +```python +class TreeNode: + def __init__(self, x): + self.val = x + self.left = None + self.right = None + + +class ListNode: + def __init__(self, x): + self.val = x + self.next = None + + +class TreeNode(object): + def __init__(self, val=0, left=None, right=None): + self.val = val + self.left = left + self.right = right + + +class Solution: + def sortedListToBST(self, head: ListNode) -> TreeNode: + + arr = [] + cur = head + while cur: + arr.append(cur.val) + cur = cur.next + return self.dfs(arr) + + def dfs(self, arr): + if not arr: + return + m = len(arr) // 2 + root = TreeNode(arr[m]) + root.left = self.dfs(arr[:m]) + root.right = self.dfs(arr[m + 1 :]) + return root + +``` + +## 答案 + +```python + +``` + +## 选项 + +### A + +```python + +``` + +### B + +```python + +``` + +### C + +```python + +``` \ No newline at end of file diff --git "a/data/2.dailycode\344\270\255\351\230\266/3.python/113.exercises/config.json" "b/data/2.dailycode\344\270\255\351\230\266/3.python/113.exercises/config.json" new file mode 100644 index 00000000..b1bba924 --- /dev/null +++ "b/data/2.dailycode\344\270\255\351\230\266/3.python/113.exercises/config.json" @@ -0,0 +1,10 @@ +{ + "node_id": "dailycode-bc6edef11e3a47a787ee47a8dd4bc00b", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [], + "export": [ + "solution.json" + ] +} \ No newline at end of file diff --git "a/data/2.dailycode\344\270\255\351\230\266/3.python/113.exercises/solution.json" "b/data/2.dailycode\344\270\255\351\230\266/3.python/113.exercises/solution.json" new file mode 100644 index 00000000..a30ea7be --- /dev/null +++ "b/data/2.dailycode\344\270\255\351\230\266/3.python/113.exercises/solution.json" @@ -0,0 +1,7 @@ +{ + "type": "code_options", + "source": "solution.md", + "exercise_id": "e8cbf541031d4cd09451b10cc48997ef", + "author": "csdn.net", + "keywords": "树,深度优先搜索,回溯,二叉树" +} \ No newline at end of file diff --git "a/data/2.dailycode\344\270\255\351\230\266/3.python/113.exercises/solution.md" "b/data/2.dailycode\344\270\255\351\230\266/3.python/113.exercises/solution.md" new file mode 100644 index 00000000..dc71d015 --- /dev/null +++ "b/data/2.dailycode\344\270\255\351\230\266/3.python/113.exercises/solution.md" @@ -0,0 +1,96 @@ +# 路径总和 II + +
给你二叉树的根节点 root
和一个整数目标和 targetSum
,找出所有 从根节点到叶子节点 路径总和等于给定目标和的路径。
叶子节点 是指没有子节点的节点。
+ ++ +
示例 1:
+ ++输入:root = [5,4,8,11,null,13,4,7,2,null,null,5,1], targetSum = 22 +输出:[[5,4,11,2],[5,8,4,5]] ++ +
示例 2:
+ ++输入:root = [1,2,3], targetSum = 5 +输出:[] ++ +
示例 3:
+ ++输入:root = [1,2], targetSum = 0 +输出:[] ++ +
+ +
提示:
+ +[0, 5000]
内-1000 <= Node.val <= 1000
-1000 <= targetSum <= 1000
给你二叉树的根结点 root
,请你将它展开为一个单链表:
TreeNode
,其中 right
子指针指向链表中下一个结点,而左子指针始终为 null
。+ +
示例 1:
+ ++输入:root = [1,2,5,3,4,null,6] +输出:[1,null,2,null,3,null,4,null,5,null,6] ++ +
示例 2:
+ ++输入:root = [] +输出:[] ++ +
示例 3:
+ ++输入:root = [0] +输出:[0] ++ +
+ +
提示:
+ +[0, 2000]
内-100 <= Node.val <= 100
+ +
进阶:你可以使用原地算法(O(1)
额外空间)展开这棵树吗?
给定一个 完美二叉树 ,其所有叶子节点都在同一层,每个父节点都有两个子节点。二叉树定义如下:
+ ++struct Node { + int val; + Node *left; + Node *right; + Node *next; +}+ +
填充它的每个 next 指针,让这个指针指向其下一个右侧节点。如果找不到下一个右侧节点,则将 next 指针设置为 NULL
。
初始状态下,所有 next 指针都被设置为 NULL
。
+ +
进阶:
+ ++ +
示例:
+ + + ++输入:root = [1,2,3,4,5,6,7] +输出:[1,#,2,3,#,4,5,6,7,#] +解释:给定二叉树如图 A 所示,你的函数应该填充它的每个 next 指针,以指向其下一个右侧节点,如图 B 所示。序列化的输出按层序遍历排列,同一层节点由 next 指针连接,'#' 标志着每一层的结束。 ++ +
+ +
提示:
+ +4096
-1000 <= node.val <= 1000
给定一个二叉树
+ ++struct Node { + int val; + Node *left; + Node *right; + Node *next; +}+ +
填充它的每个 next 指针,让这个指针指向其下一个右侧节点。如果找不到下一个右侧节点,则将 next 指针设置为 NULL
。
初始状态下,所有 next 指针都被设置为 NULL
。
+ +
进阶:
+ ++ +
示例:
+ + + ++输入:root = [1,2,3,4,5,null,7] +输出:[1,#,2,3,#,4,5,7,#] +解释:给定二叉树如图 A 所示,你的函数应该填充它的每个 next 指针,以指向其下一个右侧节点,如图 B 所示。序列化输出按层序遍历顺序(由 next 指针连接),'#' 表示每层的末尾。+ +
+ +
提示:
+ +6000
-100 <= node.val <= 100
+ +
给定一个三角形 triangle
,找出自顶向下的最小路径和。
每一步只能移动到下一行中相邻的结点上。相邻的结点 在这里指的是 下标 与 上一层结点下标 相同或者等于 上一层结点下标 + 1 的两个结点。也就是说,如果正位于当前行的下标 i
,那么下一步可以移动到下一行的下标 i
或 i + 1
。
+ +
示例 1:
+ ++输入:triangle = [[2],[3,4],[6,5,7],[4,1,8,3]] +输出:11 +解释:如下面简图所示: + 2 + 3 4 + 6 5 7 +4 1 8 3 +自顶向下的最小路径和为 11(即,2 + 3 + 5 + 1 = 11)。 ++ +
示例 2:
+ ++输入:triangle = [[-10]] +输出:-10 ++ +
+ +
提示:
+ +1 <= triangle.length <= 200
triangle[0].length == 1
triangle[i].length == triangle[i - 1].length + 1
-104 <= triangle[i][j] <= 104
+ +
进阶:
+ +O(n)
的额外空间(n
为三角形的总行数)来解决这个问题吗?给定一个未排序的整数数组 nums
,找出数字连续的最长序列(不要求序列元素在原数组中连续)的长度。
请你设计并实现时间复杂度为 O(n)
的算法解决此问题。
+ +
示例 1:
+ +
+输入:nums = [100,4,200,1,3,2]
+输出:4
+解释:最长数字连续序列是 [1, 2, 3, 4]。它的长度为 4。
+
+示例 2:
+ ++输入:nums = [0,3,7,2,5,8,4,6,0,1] +输出:9 ++ +
+ +
提示:
+ +0 <= nums.length <= 105
-109 <= nums[i] <= 109
root
,树中每个节点都存放有一个 0
到 9
之间的数字。
+每条从根节点到叶节点的路径都代表一个数字:
+ +1 -> 2 -> 3
表示数字 123
。计算从根节点到叶节点生成的 所有数字之和 。
+ +叶节点 是指没有子节点的节点。
+ ++ +
示例 1:
+ ++输入:root = [1,2,3] +输出:25 +解释: +从根到叶子节点路径+ +1->2
代表数字12
+从根到叶子节点路径1->3
代表数字13
+因此,数字总和 = 12 + 13 =25
示例 2:
+ ++输入:root = [4,9,0,5,1] +输出:1026 +解释: +从根到叶子节点路径+ +4->9->5
代表数字 495 +从根到叶子节点路径4->9->1
代表数字 491 +从根到叶子节点路径4->0
代表数字 40 +因此,数字总和 = 495 + 491 + 40 =1026
+
+ +
提示:
+ +[1, 1000]
内0 <= Node.val <= 9
10
m x n
的矩阵 board
,由若干字符 'X'
和 'O'
,找到所有被 'X'
围绕的区域,并将这些区域里所有的 'O'
用 'X'
填充。
++ +
示例 1:
+ ++输入:board = [["X","X","X","X"],["X","O","O","X"],["X","X","O","X"],["X","O","X","X"]] +输出:[["X","X","X","X"],["X","X","X","X"],["X","X","X","X"],["X","O","X","X"]] +解释:被围绕的区间不会存在于边界上,换句话说,任何边界上的+ +'O'
都不会被填充为'X'
。 任何不在边界上,或不与边界上的'O'
相连的'O'
最终都会被填充为'X'
。如果两个元素在水平或垂直方向相邻,则称它们是“相连”的。 +
示例 2:
+ ++输入:board = [["X"]] +输出:[["X"]] ++ +
+ +
提示:
+ +m == board.length
n == board[i].length
1 <= m, n <= 200
board[i][j]
为 'X'
或 'O'
给你一个字符串 s
,请你将 s
分割成一些子串,使每个子串都是 回文串 。返回 s
所有可能的分割方案。
回文串 是正着读和反着读都一样的字符串。
+ ++ +
示例 1:
+ ++输入:s = "aab" +输出:[["a","a","b"],["aa","b"]] ++ +
示例 2:
+ ++输入:s = "a" +输出:[["a"]] ++ +
+ +
提示:
+ +1 <= s.length <= 16
s
仅由小写英文字母组成给你无向 连通 图中一个节点的引用,请你返回该图的 深拷贝(克隆)。
+ +图中的每个节点都包含它的值 val
(int
) 和其邻居的列表(list[Node]
)。
class Node { + public int val; + public List<Node> neighbors; +}+ +
+ +
测试用例格式:
+ +简单起见,每个节点的值都和它的索引相同。例如,第一个节点值为 1(val = 1
),第二个节点值为 2(val = 2
),以此类推。该图在测试用例中使用邻接列表表示。
邻接列表 是用于表示有限图的无序列表的集合。每个列表都描述了图中节点的邻居集。
+ +给定节点将始终是图中的第一个节点(值为 1)。你必须将 给定节点的拷贝 作为对克隆图的引用返回。
+ ++ +
示例 1:
+ + + +输入:adjList = [[2,4],[1,3],[2,4],[1,3]] +输出:[[2,4],[1,3],[2,4],[1,3]] +解释: +图中有 4 个节点。 +节点 1 的值是 1,它有两个邻居:节点 2 和 4 。 +节点 2 的值是 2,它有两个邻居:节点 1 和 3 。 +节点 3 的值是 3,它有两个邻居:节点 2 和 4 。 +节点 4 的值是 4,它有两个邻居:节点 1 和 3 。 ++ +
示例 2:
+ + + +输入:adjList = [[]] +输出:[[]] +解释:输入包含一个空列表。该图仅仅只有一个值为 1 的节点,它没有任何邻居。 ++ +
示例 3:
+ +输入:adjList = [] +输出:[] +解释:这个图是空的,它不含任何节点。 ++ +
示例 4:
+ + + +输入:adjList = [[2],[1]] +输出:[[2],[1]]+ +
+ +
提示:
+ +Node.val
都是唯一的,1 <= Node.val <= 100
。在一条环路上有 N 个加油站,其中第 i 个加油站有汽油 gas[i]
升。
你有一辆油箱容量无限的的汽车,从第 i 个加油站开往第 i+1 个加油站需要消耗汽油 cost[i]
升。你从其中的一个加油站出发,开始时油箱为空。
如果你可以绕环路行驶一周,则返回出发时加油站的编号,否则返回 -1。
+ +说明:
+ +示例 1:
+ +输入: +gas = [1,2,3,4,5] +cost = [3,4,5,1,2] + +输出: 3 + +解释: +从 3 号加油站(索引为 3 处)出发,可获得 4 升汽油。此时油箱有 = 0 + 4 = 4 升汽油 +开往 4 号加油站,此时油箱有 4 - 1 + 5 = 8 升汽油 +开往 0 号加油站,此时油箱有 8 - 2 + 1 = 7 升汽油 +开往 1 号加油站,此时油箱有 7 - 3 + 2 = 6 升汽油 +开往 2 号加油站,此时油箱有 6 - 4 + 3 = 5 升汽油 +开往 3 号加油站,你需要消耗 5 升汽油,正好足够你返回到 3 号加油站。 +因此,3 可为起始索引。+ +
示例 2:
+ +输入: +gas = [2,3,4] +cost = [3,4,3] + +输出: -1 + +解释: +你不能从 0 号或 1 号加油站出发,因为没有足够的汽油可以让你行驶到下一个加油站。 +我们从 2 号加油站出发,可以获得 4 升汽油。 此时油箱有 = 0 + 4 = 4 升汽油 +开往 0 号加油站,此时油箱有 4 - 3 + 2 = 3 升汽油 +开往 1 号加油站,此时油箱有 3 - 3 + 3 = 3 升汽油 +你无法返回 2 号加油站,因为返程需要消耗 4 升汽油,但是你的油箱只有 3 升汽油。 +因此,无论怎样,你都不可能绕环路行驶一周。+ + +## template + +```python +class Solution(object): + def canCompleteCircuit(self, gas, cost): + """ + :type gas: List[int] + :type cost: List[int] + :rtype: int + """ + n = len(gas) + if sum(gas) < sum(cost): + return -1 + else: + start = 0 + path = 0 + for i in range(n): + path = path + (gas[i] - cost[i]) + if path < 0: + start = i + 1 + path = 0 + return start + + +``` + +## 答案 + +```python + +``` + +## 选项 + +### A + +```python + +``` + +### B + +```python + +``` + +### C + +```python + +``` \ No newline at end of file diff --git "a/data/2.dailycode\344\270\255\351\230\266/3.python/137.exercises/config.json" "b/data/2.dailycode\344\270\255\351\230\266/3.python/137.exercises/config.json" new file mode 100644 index 00000000..9b0125c3 --- /dev/null +++ "b/data/2.dailycode\344\270\255\351\230\266/3.python/137.exercises/config.json" @@ -0,0 +1,10 @@ +{ + "node_id": "dailycode-e0c8fae20b664ff3a1d728dba5024174", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [], + "export": [ + "solution.json" + ] +} \ No newline at end of file diff --git "a/data/2.dailycode\344\270\255\351\230\266/3.python/137.exercises/solution.json" "b/data/2.dailycode\344\270\255\351\230\266/3.python/137.exercises/solution.json" new file mode 100644 index 00000000..ed77755a --- /dev/null +++ "b/data/2.dailycode\344\270\255\351\230\266/3.python/137.exercises/solution.json" @@ -0,0 +1,7 @@ +{ + "type": "code_options", + "source": "solution.md", + "exercise_id": "29824658e1d54db1a7184adbd1e37516", + "author": "csdn.net", + "keywords": "位运算,数组" +} \ No newline at end of file diff --git "a/data/2.dailycode\344\270\255\351\230\266/3.python/137.exercises/solution.md" "b/data/2.dailycode\344\270\255\351\230\266/3.python/137.exercises/solution.md" new file mode 100644 index 00000000..8bb220de --- /dev/null +++ "b/data/2.dailycode\344\270\255\351\230\266/3.python/137.exercises/solution.md" @@ -0,0 +1,79 @@ +# 只出现一次的数字 II + +
给你一个整数数组 nums
,除某个元素仅出现 一次 外,其余每个元素都恰出现 三次 。请你找出并返回那个只出现了一次的元素。
+ +
示例 1:
+ ++输入:nums = [2,2,3,2] +输出:3 ++ +
示例 2:
+ ++输入:nums = [0,1,0,1,0,1,99] +输出:99 ++ +
+ +
提示:
+ +1 <= nums.length <= 3 * 104
-231 <= nums[i] <= 231 - 1
nums
中,除某个元素仅出现 一次 外,其余每个元素都恰出现 三次+ +
进阶:你的算法应该具有线性时间复杂度。 你可以不使用额外空间来实现吗?
+ + +## template + +```python + +class Solution(object): + def singleNumber(self, nums): + """ + :type nums: List[int] + :rtype: int + """ + a = 0 + b = 0 + for num in nums: + a = (num ^ a) & ~b + b = (num ^ b) & ~a + return a + +``` + +## 答案 + +```python + +``` + +## 选项 + +### A + +```python + +``` + +### B + +```python + +``` + +### C + +```python + +``` \ No newline at end of file diff --git "a/data/2.dailycode\344\270\255\351\230\266/3.python/138.exercises/config.json" "b/data/2.dailycode\344\270\255\351\230\266/3.python/138.exercises/config.json" new file mode 100644 index 00000000..f4bf4fd2 --- /dev/null +++ "b/data/2.dailycode\344\270\255\351\230\266/3.python/138.exercises/config.json" @@ -0,0 +1,10 @@ +{ + "node_id": "dailycode-80a3b8ff74db43638f416d2e1bf6b17f", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [], + "export": [ + "solution.json" + ] +} \ No newline at end of file diff --git "a/data/2.dailycode\344\270\255\351\230\266/3.python/138.exercises/solution.json" "b/data/2.dailycode\344\270\255\351\230\266/3.python/138.exercises/solution.json" new file mode 100644 index 00000000..613ea7d6 --- /dev/null +++ "b/data/2.dailycode\344\270\255\351\230\266/3.python/138.exercises/solution.json" @@ -0,0 +1,7 @@ +{ + "type": "code_options", + "source": "solution.md", + "exercise_id": "56d73a6c6fc14885aca55e785ee7b1e6", + "author": "csdn.net", + "keywords": "哈希表,链表" +} \ No newline at end of file diff --git "a/data/2.dailycode\344\270\255\351\230\266/3.python/138.exercises/solution.md" "b/data/2.dailycode\344\270\255\351\230\266/3.python/138.exercises/solution.md" new file mode 100644 index 00000000..258d3d65 --- /dev/null +++ "b/data/2.dailycode\344\270\255\351\230\266/3.python/138.exercises/solution.md" @@ -0,0 +1,127 @@ +# 复制带随机指针的链表 + +给你一个长度为 n
的链表,每个节点包含一个额外增加的随机指针 random
,该指针可以指向链表中的任何节点或空节点。
构造这个链表的 深拷贝。 深拷贝应该正好由 n
个 全新 节点组成,其中每个新节点的值都设为其对应的原节点的值。新节点的 next
指针和 random
指针也都应指向复制链表中的新节点,并使原链表和复制链表中的这些指针能够表示相同的链表状态。复制链表中的指针都不应指向原链表中的节点 。
例如,如果原链表中有 X
和 Y
两个节点,其中 X.random --> Y
。那么在复制链表中对应的两个节点 x
和 y
,同样有 x.random --> y
。
返回复制链表的头节点。
+ +用一个由 n
个节点组成的链表来表示输入/输出中的链表。每个节点用一个 [val, random_index]
表示:
val
:一个表示 Node.val
的整数。random_index
:随机指针指向的节点索引(范围从 0
到 n-1
);如果不指向任何节点,则为 null
。你的代码 只 接受原链表的头节点 head
作为传入参数。
+ +
示例 1:
+ + + ++输入:head = [[7,null],[13,0],[11,4],[10,2],[1,0]] +输出:[[7,null],[13,0],[11,4],[10,2],[1,0]] ++ +
示例 2:
+ + + ++输入:head = [[1,1],[2,1]] +输出:[[1,1],[2,1]] ++ +
示例 3:
+ ++ +
+输入:head = [[3,null],[3,0],[3,null]] +输出:[[3,null],[3,0],[3,null]] ++ +
示例 4:
+ ++输入:head = [] +输出:[] +解释:给定的链表为空(空指针),因此返回 null。 ++ +
+ +
提示:
+ +0 <= n <= 1000
-10000 <= Node.val <= 10000
Node.random
为空(null)或指向链表中的节点。给定一个非空字符串 s 和一个包含非空单词的列表 wordDict,判定 s 是否可以被空格拆分为一个或多个在字典中出现的单词。
+ +说明:
+ +示例 1:
+ +输入: s = "leetcode", wordDict = ["leet", "code"] +输出: true +解释: 返回 true 因为 "leetcode" 可以被拆分成 "leet code"。 ++ +
示例 2:
+ +输入: s = "applepenapple", wordDict = ["apple", "pen"] +输出: true +解释: 返回 true 因为+ +"
applepenapple"
可以被拆分成"
apple pen apple"
。 + 注意你可以重复使用字典中的单词。 +
示例 3:
+ +输入: s = "catsandog", wordDict = ["cats", "dog", "sand", "and", "cat"] +输出: false ++ + +## template + +```python + +class Solution(object): + def wordBreak(self, s, wordDict): + """ + :type s: str + :type wordDict: List[str] + :rtype: bool + """ + if not s: + return True + lenth = len(s) + dp = [False for i in range(lenth + 1)] + dp[0] = True + for i in range(1, lenth + 1): + for j in range(i): + if dp[j] and s[j:i] in wordDict: + dp[i] = True + break + return dp[-1] + +``` + +## 答案 + +```python + +``` + +## 选项 + +### A + +```python + +``` + +### B + +```python + +``` + +### C + +```python + +``` \ No newline at end of file diff --git "a/data/2.dailycode\344\270\255\351\230\266/3.python/142.exercises/config.json" "b/data/2.dailycode\344\270\255\351\230\266/3.python/142.exercises/config.json" new file mode 100644 index 00000000..28ee3c7d --- /dev/null +++ "b/data/2.dailycode\344\270\255\351\230\266/3.python/142.exercises/config.json" @@ -0,0 +1,10 @@ +{ + "node_id": "dailycode-acfd338816284b2a9706de1da46b2937", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [], + "export": [ + "solution.json" + ] +} \ No newline at end of file diff --git "a/data/2.dailycode\344\270\255\351\230\266/3.python/142.exercises/solution.json" "b/data/2.dailycode\344\270\255\351\230\266/3.python/142.exercises/solution.json" new file mode 100644 index 00000000..012fb072 --- /dev/null +++ "b/data/2.dailycode\344\270\255\351\230\266/3.python/142.exercises/solution.json" @@ -0,0 +1,7 @@ +{ + "type": "code_options", + "source": "solution.md", + "exercise_id": "8a80ca04f6ef482a9ce79e7043387844", + "author": "csdn.net", + "keywords": "哈希表,链表,双指针" +} \ No newline at end of file diff --git "a/data/2.dailycode\344\270\255\351\230\266/3.python/142.exercises/solution.md" "b/data/2.dailycode\344\270\255\351\230\266/3.python/142.exercises/solution.md" new file mode 100644 index 00000000..90582731 --- /dev/null +++ "b/data/2.dailycode\344\270\255\351\230\266/3.python/142.exercises/solution.md" @@ -0,0 +1,105 @@ +# 环形链表 II + +
给定一个链表,返回链表开始入环的第一个节点。 如果链表无环,则返回 null
。
为了表示给定链表中的环,我们使用整数 pos
来表示链表尾连接到链表中的位置(索引从 0 开始)。 如果 pos
是 -1
,则在该链表中没有环。注意,pos
仅仅是用于标识环的情况,并不会作为参数传递到函数中。
说明:不允许修改给定的链表。
+ +进阶:
+ +O(1)
空间解决此题?+ +
示例 1:
+ + + ++输入:head = [3,2,0,-4], pos = 1 +输出:返回索引为 1 的链表节点 +解释:链表中有一个环,其尾部连接到第二个节点。 ++ +
示例 2:
+ + + ++输入:head = [1,2], pos = 0 +输出:返回索引为 0 的链表节点 +解释:链表中有一个环,其尾部连接到第一个节点。 ++ +
示例 3:
+ + + ++输入:head = [1], pos = -1 +输出:返回 null +解释:链表中没有环。 ++ +
+ +
提示:
+ +[0, 104]
内-105 <= Node.val <= 105
pos
的值为 -1
或者链表中的一个有效索引给定一个单链表 L
的头节点 head
,单链表 L
表示为:
L0 → L1 → … → Ln-1 → Ln
+请将其重新排列后变为:
L0 → Ln → L1 → Ln-1 → L2 → Ln-2 → …
不能只是单纯的改变节点内部的值,而是需要实际的进行节点交换。
+ ++ +
示例 1:
+ + + ++输入: head = [1,2,3,4] +输出: [1,4,2,3]+ +
示例 2:
+ + + ++输入: head = [1,2,3,4,5] +输出: [1,5,2,4,3]+ +
+ +
提示:
+ +[1, 5 * 104]
1 <= node.val <= 1000
实现 LRUCache
类:
LRUCache(int capacity)
以正整数作为容量 capacity
初始化 LRU 缓存int get(int key)
如果关键字 key
存在于缓存中,则返回关键字的值,否则返回 -1
。void put(int key, int value)
如果关键字已经存在,则变更其数据值;如果关键字不存在,则插入该组「关键字-值」。当缓存容量达到上限时,它应该在写入新数据之前删除最久未使用的数据值,从而为新的数据值留出空间。+
进阶:你是否可以在 O(1)
时间复杂度内完成这两种操作?
+ +
示例:
+ ++输入 +["LRUCache", "put", "put", "get", "put", "get", "put", "get", "get", "get"] +[[2], [1, 1], [2, 2], [1], [3, 3], [2], [4, 4], [1], [3], [4]] +输出 +[null, null, null, 1, null, -1, null, -1, 3, 4] + +解释 +LRUCache lRUCache = new LRUCache(2); +lRUCache.put(1, 1); // 缓存是 {1=1} +lRUCache.put(2, 2); // 缓存是 {1=1, 2=2} +lRUCache.get(1); // 返回 1 +lRUCache.put(3, 3); // 该操作会使得关键字 2 作废,缓存是 {1=1, 3=3} +lRUCache.get(2); // 返回 -1 (未找到) +lRUCache.put(4, 4); // 该操作会使得关键字 1 作废,缓存是 {4=4, 3=3} +lRUCache.get(1); // 返回 -1 (未找到) +lRUCache.get(3); // 返回 3 +lRUCache.get(4); // 返回 4 ++ +
+ +
提示:
+ +1 <= capacity <= 3000
0 <= key <= 10000
0 <= value <= 105
2 * 105
次 get
和 put
对链表进行插入排序。
+ +
+插入排序的动画演示如上。从第一个元素开始,该链表可以被认为已经部分排序(用黑色表示)。
+每次迭代时,从输入数据中移除一个元素(用红色表示),并原地将其插入到已排好序的链表中。
+ +
插入排序算法:
+ ++ +
示例 1:
+ +输入: 4->2->1->3 +输出: 1->2->3->4 ++ +
示例 2:
+ +输入: -1->5->3->4->0 +输出: -1->0->3->4->5 ++ + +## template + +```python + +class LRUCache: + def __init__(self, capacity): + """ + :type capacity: int + """ + self.maxlength = capacity + self.array = {} + self.array_list = [] + + def get(self, key): + """ + :type key: int + :rtype: int + """ + value = self.array.get(key) + + if value is not None and self.array_list[0] is not key: + index = self.array_list.index(key) + self.array_list.pop(index) + self.array_list.insert(0, key) + + value = value if value is not None else -1 + return value + + def put(self, key, value): + """ + :type key: int + :type value: int + :rtype: void + """ + + if self.array.get(key) is not None: + index = self.array_list.index(key) + self.array.pop(key) + self.array_list.pop(index) + + if len(self.array_list) >= self.maxlength: + key_t = self.array_list.pop(self.maxlength - 1) + self.array.pop(key_t) + + self.array[key] = value + self.array_list.insert(0, key) + + +``` + +## 答案 + +```python + +``` + +## 选项 + +### A + +```python + +``` + +### B + +```python + +``` + +### C + +```python + +``` \ No newline at end of file diff --git "a/data/2.dailycode\344\270\255\351\230\266/3.python/148.exercises/config.json" "b/data/2.dailycode\344\270\255\351\230\266/3.python/148.exercises/config.json" new file mode 100644 index 00000000..19a78d18 --- /dev/null +++ "b/data/2.dailycode\344\270\255\351\230\266/3.python/148.exercises/config.json" @@ -0,0 +1,10 @@ +{ + "node_id": "dailycode-9a227370e4814fcf8f3dd19a2a34d72b", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [], + "export": [ + "solution.json" + ] +} \ No newline at end of file diff --git "a/data/2.dailycode\344\270\255\351\230\266/3.python/148.exercises/solution.json" "b/data/2.dailycode\344\270\255\351\230\266/3.python/148.exercises/solution.json" new file mode 100644 index 00000000..115cd5c0 --- /dev/null +++ "b/data/2.dailycode\344\270\255\351\230\266/3.python/148.exercises/solution.json" @@ -0,0 +1,7 @@ +{ + "type": "code_options", + "source": "solution.md", + "exercise_id": "e2730b7376764544a6ea927fa978001f", + "author": "csdn.net", + "keywords": "链表,双指针,分治,排序,归并排序" +} \ No newline at end of file diff --git "a/data/2.dailycode\344\270\255\351\230\266/3.python/148.exercises/solution.md" "b/data/2.dailycode\344\270\255\351\230\266/3.python/148.exercises/solution.md" new file mode 100644 index 00000000..20b37e58 --- /dev/null +++ "b/data/2.dailycode\344\270\255\351\230\266/3.python/148.exercises/solution.md" @@ -0,0 +1,121 @@ +# 排序链表 + +
给你链表的头结点 head
,请将其按 升序 排列并返回 排序后的链表 。
进阶:
+ +O(n log n)
时间复杂度和常数级空间复杂度下,对链表进行排序吗?+ +
示例 1:
+ ++输入:head = [4,2,1,3] +输出:[1,2,3,4] ++ +
示例 2:
+ ++输入:head = [-1,5,3,4,0] +输出:[-1,0,3,4,5] ++ +
示例 3:
+ ++输入:head = [] +输出:[] ++ +
+ +
提示:
+ +[0, 5 * 104]
内-105 <= Node.val <= 105
根据 逆波兰表示法,求表达式的值。
+ +有效的算符包括 +
、-
、*
、/
。每个运算对象可以是整数,也可以是另一个逆波兰表达式。
+ +
说明:
+ ++ +
示例 1:
+ ++输入:tokens = ["2","1","+","3","*"] +输出:9 +解释:该算式转化为常见的中缀算术表达式为:((2 + 1) * 3) = 9 ++ +
示例 2:
+ ++输入:tokens = ["4","13","5","/","+"] +输出:6 +解释:该算式转化为常见的中缀算术表达式为:(4 + (13 / 5)) = 6 ++ +
示例 3:
+ ++输入:tokens = ["10","6","9","3","+","-11","*","/","*","17","+","5","+"] +输出:22 +解释: +该算式转化为常见的中缀算术表达式为: + ((10 * (6 / ((9 + 3) * -11))) + 17) + 5 += ((10 * (6 / (12 * -11))) + 17) + 5 += ((10 * (6 / -132)) + 17) + 5 += ((10 * 0) + 17) + 5 += (0 + 17) + 5 += 17 + 5 += 22+ +
+ +
提示:
+ +1 <= tokens.length <= 104
tokens[i]
要么是一个算符("+"
、"-"
、"*"
或 "/"
),要么是一个在范围 [-200, 200]
内的整数+ +
逆波兰表达式:
+ +逆波兰表达式是一种后缀表达式,所谓后缀就是指算符写在后面。
+ +( 1 + 2 ) * ( 3 + 4 )
。( ( 1 2 + ) ( 3 4 + ) * )
。逆波兰表达式主要有以下两个优点:
+ +1 2 + 3 4 + *
也可以依据次序计算出正确结果。给你一个字符串 s
,逐个翻转字符串中的所有 单词 。
单词 是由非空格字符组成的字符串。s
中使用至少一个空格将字符串中的 单词 分隔开。
请你返回一个翻转 s
中单词顺序并用单个空格相连的字符串。
说明:
+ +s
可以在前面、后面或者单词间包含多余的空格。+ +
示例 1:
+ ++输入:s = "+ +the sky is blue
" +输出:"blue is sky the
" +
示例 2:
+ ++输入:s = " hello world " +输出:"world hello" +解释:输入字符串可以在前面或者后面包含多余的空格,但是翻转后的字符不能包括。 ++ +
示例 3:
+ ++输入:s = "a good example" +输出:"example good a" +解释:如果两个单词间有多余的空格,将翻转后单词间的空格减少到只含一个。 ++ +
示例 4:
+ ++输入:s = " Bob Loves Alice " +输出:"Alice Loves Bob" ++ +
示例 5:
+ ++输入:s = "Alice does not even like bob" +输出:"bob like even not does Alice" ++ +
+ +
提示:
+ +1 <= s.length <= 104
s
包含英文大小写字母、数字和空格 ' '
s
中 至少存在一个 单词+ +
进阶:
+ +O(1)
额外空间复杂度的原地解法。给你一个整数数组 nums
,请你找出数组中乘积最大的连续子数组(该子数组中至少包含一个数字),并返回该子数组所对应的乘积。
+ +
示例 1:
+ +输入: [2,3,-2,4]
+输出: 6
+解释: 子数组 [2,3] 有最大乘积 6。
+
+
+示例 2:
+ +输入: [-2,0,-1] +输出: 0 +解释: 结果不能为 2, 因为 [-2,-1] 不是子数组。+ + +## template + +```python + +class Solution: + def maxProduct(self, nums: List[int]) -> int: + if len(nums) == 0: + return 0 + + length = len(nums) + + dp = [[0] * 2 for _ in range(length)] + + dp[0][0] = nums[0] + dp[0][1] = nums[0] + + for i in range(1, length): + + if nums[i] > 0: + dp[i][0] = min(nums[i], dp[i - 1][0] * nums[i]) + dp[i][1] = max(nums[i], dp[i - 1][1] * nums[i]) + else: + dp[i][0] = min(nums[i], dp[i - 1][1] * nums[i]) + dp[i][1] = max(nums[i], dp[i - 1][0] * nums[i]) + + res = dp[0][1] + for i in range(1, length): + res = max(res, dp[i][1]) + return res + +``` + +## 答案 + +```python + +``` + +## 选项 + +### A + +```python + +``` + +### B + +```python + +``` + +### C + +```python + +``` \ No newline at end of file diff --git "a/data/2.dailycode\344\270\255\351\230\266/3.python/153.exercises/config.json" "b/data/2.dailycode\344\270\255\351\230\266/3.python/153.exercises/config.json" new file mode 100644 index 00000000..6e3e748f --- /dev/null +++ "b/data/2.dailycode\344\270\255\351\230\266/3.python/153.exercises/config.json" @@ -0,0 +1,10 @@ +{ + "node_id": "dailycode-f78820577e5c4c2bbfe22cf3a0876ea9", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [], + "export": [ + "solution.json" + ] +} \ No newline at end of file diff --git "a/data/2.dailycode\344\270\255\351\230\266/3.python/153.exercises/solution.json" "b/data/2.dailycode\344\270\255\351\230\266/3.python/153.exercises/solution.json" new file mode 100644 index 00000000..2ba9cb10 --- /dev/null +++ "b/data/2.dailycode\344\270\255\351\230\266/3.python/153.exercises/solution.json" @@ -0,0 +1,7 @@ +{ + "type": "code_options", + "source": "solution.md", + "exercise_id": "c4942f6c3e044ee8a72480829e7932ad", + "author": "csdn.net", + "keywords": "数组,二分查找" +} \ No newline at end of file diff --git "a/data/2.dailycode\344\270\255\351\230\266/3.python/153.exercises/solution.md" "b/data/2.dailycode\344\270\255\351\230\266/3.python/153.exercises/solution.md" new file mode 100644 index 00000000..95cd2d43 --- /dev/null +++ "b/data/2.dailycode\344\270\255\351\230\266/3.python/153.exercises/solution.md" @@ -0,0 +1,101 @@ +# 寻找旋转排序数组中的最小值 + +已知一个长度为
n
的数组,预先按照升序排列,经由 1
到 n
次 旋转 后,得到输入数组。例如,原数组 nums = [0,1,2,4,5,6,7]
在变化后可能得到:
+4
次,则可以得到 [4,5,6,7,0,1,2]
7
次,则可以得到 [0,1,2,4,5,6,7]
注意,数组 [a[0], a[1], a[2], ..., a[n-1]]
旋转一次 的结果为数组 [a[n-1], a[0], a[1], a[2], ..., a[n-2]]
。
给你一个元素值 互不相同 的数组 nums
,它原来是一个升序排列的数组,并按上述情形进行了多次旋转。请你找出并返回数组中的 最小元素 。
+ +
示例 1:
+ ++输入:nums = [3,4,5,1,2] +输出:1 +解释:原数组为 [1,2,3,4,5] ,旋转 3 次得到输入数组。 ++ +
示例 2:
+ ++输入:nums = [4,5,6,7,0,1,2] +输出:0 +解释:原数组为 [0,1,2,4,5,6,7] ,旋转 4 次得到输入数组。 ++ +
示例 3:
+ ++输入:nums = [11,13,15,17] +输出:11 +解释:原数组为 [11,13,15,17] ,旋转 4 次得到输入数组。 ++ +
+ +
提示:
+ +n == nums.length
1 <= n <= 5000
-5000 <= nums[i] <= 5000
nums
中的所有整数 互不相同nums
原来是一个升序排序的数组,并进行了 1
至 n
次旋转峰值元素是指其值严格大于左右相邻值的元素。
+ +给你一个整数数组 nums
,找到峰值元素并返回其索引。数组可能包含多个峰值,在这种情况下,返回 任何一个峰值 所在位置即可。
你可以假设 nums[-1] = nums[n] = -∞
。
你必须实现时间复杂度为 O(log n)
的算法来解决此问题。
+ +
示例 1:
+ +
+输入:nums = [1,2,3,1]
+输出:2
+解释:3 是峰值元素,你的函数应该返回其索引 2。
+
+示例 2:
+ +
+输入:nums = [
1,2,1,3,5,6,4]
+输出:1 或 5
+解释:你的函数可以返回索引 1,其峰值元素为 2;
+ 或者返回索引 5, 其峰值元素为 6。
+
+
++ +
提示:
+ +1 <= nums.length <= 1000
-231 <= nums[i] <= 231 - 1
i
都有 nums[i] != nums[i + 1]
给你两个版本号 version1
和 version2
,请你比较它们。
版本号由一个或多个修订号组成,各修订号由一个 '.'
连接。每个修订号由 多位数字 组成,可能包含 前导零 。每个版本号至少包含一个字符。修订号从左到右编号,下标从 0 开始,最左边的修订号下标为 0 ,下一个修订号下标为 1 ,以此类推。例如,2.5.33
和 0.1
都是有效的版本号。
比较版本号时,请按从左到右的顺序依次比较它们的修订号。比较修订号时,只需比较 忽略任何前导零后的整数值 。也就是说,修订号 1
和修订号 001
相等 。如果版本号没有指定某个下标处的修订号,则该修订号视为 0
。例如,版本 1.0
小于版本 1.1
,因为它们下标为 0
的修订号相同,而下标为 1
的修订号分别为 0
和 1
,0 < 1
。
返回规则如下:
+ +version1 > version2
返回 1
,version1 < version2
返回 -1
,0
。+ +
示例 1:
+ ++输入:version1 = "1.01", version2 = "1.001" +输出:0 +解释:忽略前导零,"01" 和 "001" 都表示相同的整数 "1" ++ +
示例 2:
+ ++输入:version1 = "1.0", version2 = "1.0.0" +输出:0 +解释:version1 没有指定下标为 2 的修订号,即视为 "0" ++ +
示例 3:
+ ++输入:version1 = "0.1", version2 = "1.1" +输出:-1 +解释:version1 中下标为 0 的修订号是 "0",version2 中下标为 0 的修订号是 "1" 。0 < 1,所以 version1 < version2 ++ +
示例 4:
+ ++输入:version1 = "1.0.1", version2 = "1" +输出:1 ++ +
示例 5:
+ ++输入:version1 = "7.5.2.4", version2 = "7.5.3" +输出:-1 ++ +
+ +
提示:
+ +1 <= version1.length, version2.length <= 500
version1
和 version2
仅包含数字和 '.'
version1
和 version2
都是 有效版本号version1
和 version2
的所有修订号都可以存储在 32 位整数 中给定两个整数,分别表示分数的分子 numerator
和分母 denominator
,以 字符串形式返回小数 。
如果小数部分为循环小数,则将循环的部分括在括号内。
+ +如果存在多个答案,只需返回 任意一个 。
+ +对于所有给定的输入,保证 答案字符串的长度小于 104
。
+ +
示例 1:
+ ++输入:numerator = 1, denominator = 2 +输出:"0.5" ++ +
示例 2:
+ ++输入:numerator = 2, denominator = 1 +输出:"2" ++ +
示例 3:
+ ++输入:numerator = 2, denominator = 3 +输出:"0.(6)" ++ +
示例 4:
+ ++输入:numerator = 4, denominator = 333 +输出:"0.(012)" ++ +
示例 5:
+ ++输入:numerator = 1, denominator = 5 +输出:"0.2" ++ +
+ +
提示:
+ +-231 <= numerator, denominator <= 231 - 1
denominator != 0
BSTIterator
,表示一个按中序遍历二叉搜索树(BST)的迭代器:
+BSTIterator(TreeNode root)
初始化 BSTIterator
类的一个对象。BST 的根节点 root
会作为构造函数的一部分给出。指针应初始化为一个不存在于 BST 中的数字,且该数字小于 BST 中的任何元素。boolean hasNext()
如果向指针右侧遍历存在数字,则返回 true
;否则返回 false
。int next()
将指针向右移动,然后返回指针处的数字。注意,指针初始化为一个不存在于 BST 中的数字,所以对 next()
的首次调用将返回 BST 中的最小元素。
你可以假设 next()
调用总是有效的,也就是说,当调用 next()
时,BST 的中序遍历中至少存在一个下一个数字。
+ +
示例:
+ ++输入 +["BSTIterator", "next", "next", "hasNext", "next", "hasNext", "next", "hasNext", "next", "hasNext"] +[[[7, 3, 15, null, null, 9, 20]], [], [], [], [], [], [], [], [], []] +输出 +[null, 3, 7, true, 9, true, 15, true, 20, false] + +解释 +BSTIterator bSTIterator = new BSTIterator([7, 3, 15, null, null, 9, 20]); +bSTIterator.next(); // 返回 3 +bSTIterator.next(); // 返回 7 +bSTIterator.hasNext(); // 返回 True +bSTIterator.next(); // 返回 9 +bSTIterator.hasNext(); // 返回 True +bSTIterator.next(); // 返回 15 +bSTIterator.hasNext(); // 返回 True +bSTIterator.next(); // 返回 20 +bSTIterator.hasNext(); // 返回 False ++ +
+ +
提示:
+ +[1, 105]
内0 <= Node.val <= 106
105
次 hasNext
和 next
操作+ +
进阶:
+ +next()
和 hasNext()
操作均摊时间复杂度为 O(1)
,并使用 O(h)
内存。其中 h
是树的高度。给定一组非负整数 nums
,重新排列每个数的顺序(每个数不可拆分)使之组成一个最大的整数。
注意:输出结果可能非常大,所以你需要返回一个字符串而不是整数。
+ ++ +
示例 1:
+ ++输入+ +:
nums = [10,2]
+输出:"210"
示例 2:
+ ++输入+ +:
nums = [3,30,34,5,9]
+输出:"9534330"
+
示例 3:
+ +
+输入:
nums = [1]
+输出:"1"
+
+
+示例 4:
+ +
+输入:
nums = [10]
+输出:"10"
+
+
++ +
提示:
+ +1 <= nums.length <= 100
0 <= nums[i] <= 109
所有 DNA 都由一系列缩写为 'A'
,'C'
,'G'
和 'T'
的核苷酸组成,例如:"ACGAATTCCG"
。在研究 DNA 时,识别 DNA 中的重复序列有时会对研究非常有帮助。
编写一个函数来找出所有目标子串,目标子串的长度为 10,且在 DNA 字符串 s
中出现次数超过一次。
+ +
示例 1:
+ ++输入:s = "AAAAACCCCCAAAAACCCCCCAAAAAGGGTTT" +输出:["AAAAACCCCC","CCCCCAAAAA"] ++ +
示例 2:
+ ++输入:s = "AAAAAAAAAAAAA" +输出:["AAAAAAAAAA"] ++ +
+ +
提示:
+ +0 <= s.length <= 105
s[i]
为 'A'
、'C'
、'G'
或 'T'
给定一个数组,将数组中的元素向右移动 k
个位置,其中 k
是非负数。
+ +
进阶:
+ ++ +
示例 1:
+ ++输入: nums = [1,2,3,4,5,6,7], k = 3 +输出:+ +[5,6,7,1,2,3,4]
+解释: +向右旋转 1 步:[7,1,2,3,4,5,6]
+向右旋转 2 步:[6,7,1,2,3,4,5] +
向右旋转 3 步:[5,6,7,1,2,3,4]
+
示例 2:
+ ++输入:nums = [-1,-100,3,99], k = 2 +输出:[3,99,-1,-100] +解释: +向右旋转 1 步: [99,-1,-100,3] +向右旋转 2 步: [3,99,-1,-100]+ +
+ +
提示:
+ +1 <= nums.length <= 2 * 104
-231 <= nums[i] <= 231 - 1
0 <= k <= 105
你是一个专业的小偷,计划偷窃沿街的房屋。每间房内都藏有一定的现金,影响你偷窃的唯一制约因素就是相邻的房屋装有相互连通的防盗系统,如果两间相邻的房屋在同一晚上被小偷闯入,系统会自动报警。
+ +给定一个代表每个房屋存放金额的非负整数数组,计算你 不触动警报装置的情况下 ,一夜之内能够偷窃到的最高金额。
+ ++ +
示例 1:
+ ++输入:[1,2,3,1] +输出:4 +解释:偷窃 1 号房屋 (金额 = 1) ,然后偷窃 3 号房屋 (金额 = 3)。 + 偷窃到的最高金额 = 1 + 3 = 4 。+ +
示例 2:
+ ++输入:[2,7,9,3,1] +输出:12 +解释:偷窃 1 号房屋 (金额 = 2), 偷窃 3 号房屋 (金额 = 9),接着偷窃 5 号房屋 (金额 = 1)。 + 偷窃到的最高金额 = 2 + 9 + 1 = 12 。 ++ +
+ +
提示:
+ +1 <= nums.length <= 100
0 <= nums[i] <= 400
给定一个二叉树的 根节点 root
,想象自己站在它的右侧,按照从顶部到底部的顺序,返回从右侧所能看到的节点值。
+ +
示例 1:
+ + + ++输入: [1,2,3,null,5,null,4] +输出: [1,3,4] ++ +
示例 2:
+ ++输入: [1,null,3] +输出: [1,3] ++ +
示例 3:
+ ++输入: [] +输出: [] ++ +
+ +
提示:
+ +[0,100]
-100 <= Node.val <= 100
给你一个由 '1'
(陆地)和 '0'
(水)组成的的二维网格,请你计算网格中岛屿的数量。
岛屿总是被水包围,并且每座岛屿只能由水平方向和/或竖直方向上相邻的陆地连接形成。
+ +此外,你可以假设该网格的四条边均被水包围。
+ ++ +
示例 1:
+ ++输入:grid = [ + ["1","1","1","1","0"], + ["1","1","0","1","0"], + ["1","1","0","0","0"], + ["0","0","0","0","0"] +] +输出:1 ++ +
示例 2:
+ ++输入:grid = [ + ["1","1","0","0","0"], + ["1","1","0","0","0"], + ["0","0","1","0","0"], + ["0","0","0","1","1"] +] +输出:3 ++ +
+ +
提示:
+ +m == grid.length
n == grid[i].length
1 <= m, n <= 300
grid[i][j]
的值为 '0'
或 '1'
给定一个字符串 s
和一个字符串 t
,计算在 s
的子序列中 t
出现的个数。
字符串的一个 子序列 是指,通过删除一些(也可以不删除)字符且不干扰剩余字符相对位置所组成的新字符串。(例如,"ACE"
是 "ABCDE"
的一个子序列,而 "AEC"
不是)
题目数据保证答案符合 32 位带符号整数范围。
+ ++ +
示例 1:
+ ++输入:s = "rabbbit", t = "rabbit"+ ++输出
:3 +
解释: +如下图所示, 有 3 种可以从 s 中得到"rabbit" 的方案
。 +rabbbit
+rabbbit
+rabbbit
示例 2:
+ ++输入:s = "babgbag", t = "bag" ++ +输出
:5 +
解释: +如下图所示, 有 5 种可以从 s 中得到"bag" 的方案
。 +babgbag
+babgbag
+babgbag
+babgbag
+babgbag
+
+ +
提示:
+ +0 <= s.length, t.length <= 1000
s
和 t
由英文字母组成给定一个数组,它的第 i
个元素是一支给定的股票在第 i
天的价格。
设计一个算法来计算你所能获取的最大利润。你最多可以完成 两笔 交易。
+ +注意:你不能同时参与多笔交易(你必须在再次购买前出售掉之前的股票)。
+ ++ +
示例 1:
+ ++输入:prices = [3,3,5,0,0,3,1,4] +输出:6 +解释:在第 4 天(股票价格 = 0)的时候买入,在第 6 天(股票价格 = 3)的时候卖出,这笔交易所能获得利润 = 3-0 = 3 。 + 随后,在第 7 天(股票价格 = 1)的时候买入,在第 8 天 (股票价格 = 4)的时候卖出,这笔交易所能获得利润 = 4-1 = 3 。+ +
示例 2:
+ ++输入:prices = [1,2,3,4,5] +输出:4 +解释:在第 1 天(股票价格 = 1)的时候买入,在第 5 天 (股票价格 = 5)的时候卖出, 这笔交易所能获得利润 = 5-1 = 4 。 + 注意你不能在第 1 天和第 2 天接连购买股票,之后再将它们卖出。 + 因为这样属于同时参与了多笔交易,你必须在再次购买前出售掉之前的股票。 ++ +
示例 3:
+ ++输入:prices = [7,6,4,3,1] +输出:0 +解释:在这个情况下, 没有交易完成, 所以最大利润为 0。+ +
示例 4:
+ ++输入:prices = [1] +输出:0 ++ +
+ +
提示:
+ +1 <= prices.length <= 105
0 <= prices[i] <= 105
路径 被定义为一条从树中任意节点出发,沿父节点-子节点连接,达到任意节点的序列。同一个节点在一条路径序列中 至多出现一次 。该路径 至少包含一个 节点,且不一定经过根节点。
+ +路径和 是路径中各节点值的总和。
+ +给你一个二叉树的根节点 root
,返回其 最大路径和 。
+ +
示例 1:
+ ++输入:root = [1,2,3] +输出:6 +解释:最优路径是 2 -> 1 -> 3 ,路径和为 2 + 1 + 3 = 6+ +
示例 2:
+ ++输入:root = [-10,9,20,null,null,15,7] +输出:42 +解释:最优路径是 15 -> 20 -> 7 ,路径和为 15 + 20 + 7 = 42 ++ +
+ +
提示:
+ +[1, 3 * 104]
-1000 <= Node.val <= 1000
按字典 wordList
完成从单词 beginWord
到单词 endWord
转化,一个表示此过程的 转换序列 是形式上像 beginWord -> s1 -> s2 -> ... -> sk
这样的单词序列,并满足:
si
(1 <= i <= k
)必须是字典 wordList
中的单词。注意,beginWord
不必是字典 wordList
中的单词。sk == endWord
给你两个单词 beginWord
和 endWord
,以及一个字典 wordList
。请你找出并返回所有从 beginWord
到 endWord
的 最短转换序列 ,如果不存在这样的转换序列,返回一个空列表。每个序列都应该以单词列表 [beginWord, s1, s2, ..., sk]
的形式返回。
+ +
示例 1:
+ ++输入:beginWord = "hit", endWord = "cog", wordList = ["hot","dot","dog","lot","log","cog"] +输出:[["hit","hot","dot","dog","cog"],["hit","hot","lot","log","cog"]] +解释:存在 2 种最短的转换序列: +"hit" -> "hot" -> "dot" -> "dog" -> "cog" +"hit" -> "hot" -> "lot" -> "log" -> "cog" ++ +
示例 2:
+ ++输入:beginWord = "hit", endWord = "cog", wordList = ["hot","dot","dog","lot","log"] +输出:[] +解释:endWord "cog" 不在字典 wordList 中,所以不存在符合要求的转换序列。 ++ +
+ +
提示:
+ +1 <= beginWord.length <= 7
endWord.length == beginWord.length
1 <= wordList.length <= 5000
wordList[i].length == beginWord.length
beginWord
、endWord
和 wordList[i]
由小写英文字母组成beginWord != endWord
wordList
中的所有单词 互不相同字典 wordList
中从单词 beginWord
和 endWord
的 转换序列 是一个按下述规格形成的序列:
beginWord
。endWord
。wordList
中的单词。给你两个单词 beginWord
和 endWord
和一个字典 wordList
,找到从 beginWord
到 endWord
的 最短转换序列 中的 单词数目 。如果不存在这样的转换序列,返回 0。
示例 1:
+ ++输入:beginWord = "hit", endWord = "cog", wordList = ["hot","dot","dog","lot","log","cog"] +输出:5 +解释:一个最短转换序列是 "hit" -> "hot" -> "dot" -> "dog" -> "cog", 返回它的长度 5。 ++ +
示例 2:
+ ++输入:beginWord = "hit", endWord = "cog", wordList = ["hot","dot","dog","lot","log"] +输出:0 +解释:endWord "cog" 不在字典中,所以无法进行转换。+ +
+ +
提示:
+ +1 <= beginWord.length <= 10
endWord.length == beginWord.length
1 <= wordList.length <= 5000
wordList[i].length == beginWord.length
beginWord
、endWord
和 wordList[i]
由小写英文字母组成beginWord != endWord
wordList
中的所有字符串 互不相同给你一个字符串 s
,请你将 s
分割成一些子串,使每个子串都是回文。
返回符合要求的 最少分割次数 。
+ ++ +
示例 1:
+ ++输入:s = "aab" +输出:1 +解释:只需一次分割就可将 s 分割成 ["aa","b"] 这样两个回文子串。 ++ +
示例 2:
+ ++输入:s = "a" +输出:0 ++ +
示例 3:
+ ++输入:s = "ab" +输出:1 ++ +
+ +
提示:
+ +1 <= s.length <= 2000
s
仅由小写英文字母组成老师想给孩子们分发糖果,有 N 个孩子站成了一条直线,老师会根据每个孩子的表现,预先给他们评分。
+ +你需要按照以下要求,帮助老师给这些孩子分发糖果:
+ +那么这样下来,老师至少需要准备多少颗糖果呢?
+ ++ +
示例 1:
+ ++输入:[1,0,2] +输出:5 +解释:你可以分别给这三个孩子分发 2、1、2 颗糖果。 ++ +
示例 2:
+ ++输入:[1,2,2] +输出:4 +解释:你可以分别给这三个孩子分发 1、2、1 颗糖果。 + 第三个孩子只得到 1 颗糖果,这已满足上述两个条件。+ + +## template + +```python +class Solution(object): + def candy(self, ratings): + """ + :type ratings: List[int] + :rtype: int + """ + if ratings == None: + return 0 + lenth = len(ratings) + dp = [1 for i in range(lenth)] + sum = 0 + for i in range(1, len(ratings)): + if ratings[i] > ratings[i - 1]: + dp[i] = dp[i - 1] + 1 + for i in range(len(ratings) - 2, -1, -1): + if ratings[i] > ratings[i + 1] and dp[i] <= dp[i + 1]: + dp[i] = dp[i + 1] + 1 + for i in range(lenth): + sum += dp[i] + return sum + +``` + +## 答案 + +```python + +``` + +## 选项 + +### A + +```python + +``` + +### B + +```python + +``` + +### C + +```python + +``` \ No newline at end of file diff --git "a/data/3.dailycode\351\253\230\351\230\266/3.python/140.exercises/config.json" "b/data/3.dailycode\351\253\230\351\230\266/3.python/140.exercises/config.json" new file mode 100644 index 00000000..e5f71fc2 --- /dev/null +++ "b/data/3.dailycode\351\253\230\351\230\266/3.python/140.exercises/config.json" @@ -0,0 +1,10 @@ +{ + "node_id": "dailycode-c12fefc5309b4cb7842e7587a1d366a9", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [], + "export": [ + "solution.json" + ] +} \ No newline at end of file diff --git "a/data/3.dailycode\351\253\230\351\230\266/3.python/140.exercises/solution.json" "b/data/3.dailycode\351\253\230\351\230\266/3.python/140.exercises/solution.json" new file mode 100644 index 00000000..bf9f406e --- /dev/null +++ "b/data/3.dailycode\351\253\230\351\230\266/3.python/140.exercises/solution.json" @@ -0,0 +1,7 @@ +{ + "type": "code_options", + "source": "solution.md", + "exercise_id": "d28fda4f9c8149e18b8044fb166e824f", + "author": "csdn.net", + "keywords": "字典树,记忆化搜索,哈希表,字符串,动态规划,回溯" +} \ No newline at end of file diff --git "a/data/3.dailycode\351\253\230\351\230\266/3.python/140.exercises/solution.md" "b/data/3.dailycode\351\253\230\351\230\266/3.python/140.exercises/solution.md" new file mode 100644 index 00000000..45780ba6 --- /dev/null +++ "b/data/3.dailycode\351\253\230\351\230\266/3.python/140.exercises/solution.md" @@ -0,0 +1,109 @@ +# 单词拆分 II + +
给定一个非空字符串 s 和一个包含非空单词列表的字典 wordDict,在字符串中增加空格来构建一个句子,使得句子中所有的单词都在词典中。返回所有这些可能的句子。
+ +说明:
+ +示例 1:
+ +输入: +s = "+ +catsanddog
" +wordDict =["cat", "cats", "and", "sand", "dog"]
+输出: +[ + "cats and dog", + "cat sand dog" +]
+
示例 2:
+ +输入: +s = "pineapplepenapple" +wordDict = ["apple", "pen", "applepen", "pine", "pineapple"] +输出: +[ + "pine apple pen apple", + "pineapple pen apple", + "pine applepen apple" +] +解释: 注意你可以重复使用字典中的单词。 ++ +
示例 3:
+ +输入: +s = "catsandog" +wordDict = ["cats", "dog", "sand", "and", "cat"] +输出: +[] ++ + +## template + +```python +class Solution(object): + def dfs(self, low, length, s, res, vaild, path=[]): + if low == length: + res.append(" ".join(path)) + return + for i in range(low, length): + if vaild[low][i]: + self.dfs(i + 1, length, s, res, vaild, path + [s[low : i + 1]]) + + def wordBreak(self, s, wordDict): + """ + :type s: str + :type wordDict: List[str] + :rtype: List[str] + """ + length = len(s) + vaild = [[False] * length for _ in range(length)] + dp = [False for _ in range(length + 1)] + dp[0] = True + wordDict = set(wordDict) + for i in range(1, length + 1): + for j in range(i + 1): + word = s[j:i] + if dp[j] and word in wordDict: + dp[i] = True + vaild[j][i - 1] = True + res = [] + if dp[-1]: + self.dfs(0, length, s, res, vaild) + return res + + +``` + +## 答案 + +```python + +``` + +## 选项 + +### A + +```python + +``` + +### B + +```python + +``` + +### C + +```python + +``` \ No newline at end of file diff --git "a/data/3.dailycode\351\253\230\351\230\266/3.python/149.exercises/config.json" "b/data/3.dailycode\351\253\230\351\230\266/3.python/149.exercises/config.json" new file mode 100644 index 00000000..8537b0bf --- /dev/null +++ "b/data/3.dailycode\351\253\230\351\230\266/3.python/149.exercises/config.json" @@ -0,0 +1,10 @@ +{ + "node_id": "dailycode-4654129f5c054b9db02fbdb1d7ad643b", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [], + "export": [ + "solution.json" + ] +} \ No newline at end of file diff --git "a/data/3.dailycode\351\253\230\351\230\266/3.python/149.exercises/solution.json" "b/data/3.dailycode\351\253\230\351\230\266/3.python/149.exercises/solution.json" new file mode 100644 index 00000000..41b0974a --- /dev/null +++ "b/data/3.dailycode\351\253\230\351\230\266/3.python/149.exercises/solution.json" @@ -0,0 +1,7 @@ +{ + "type": "code_options", + "source": "solution.md", + "exercise_id": "c46851f1de3a4abfba2e35193034607a", + "author": "csdn.net", + "keywords": "几何,哈希表,数学" +} \ No newline at end of file diff --git "a/data/3.dailycode\351\253\230\351\230\266/3.python/149.exercises/solution.md" "b/data/3.dailycode\351\253\230\351\230\266/3.python/149.exercises/solution.md" new file mode 100644 index 00000000..b9692a5a --- /dev/null +++ "b/data/3.dailycode\351\253\230\351\230\266/3.python/149.exercises/solution.md" @@ -0,0 +1,91 @@ +# 直线上最多的点数 + +
给你一个数组 points
,其中 points[i] = [xi, yi]
表示 X-Y 平面上的一个点。求最多有多少个点在同一条直线上。
+ +
示例 1:
+ ++输入:points = [[1,1],[2,2],[3,3]] +输出:3 ++ +
示例 2:
+ ++输入:points = [[1,1],[3,2],[5,3],[4,1],[2,3],[1,4]] +输出:4 ++ +
+ +
提示:
+ +1 <= points.length <= 300
points[i].length == 2
-104 <= xi, yi <= 104
points
中的所有点 互不相同n
的数组,预先按照升序排列,经由 1
到 n
次 旋转 后,得到输入数组。例如,原数组 nums = [0,1,4,4,5,6,7]
在变化后可能得到:
+4
次,则可以得到 [4,5,6,7,0,1,4]
7
次,则可以得到 [0,1,4,4,5,6,7]
注意,数组 [a[0], a[1], a[2], ..., a[n-1]]
旋转一次 的结果为数组 [a[n-1], a[0], a[1], a[2], ..., a[n-2]]
。
给你一个可能存在 重复 元素值的数组 nums
,它原来是一个升序排列的数组,并按上述情形进行了多次旋转。请你找出并返回数组中的 最小元素 。
+ +
示例 1:
+ ++输入:nums = [1,3,5] +输出:1 ++ +
示例 2:
+ ++输入:nums = [2,2,2,0,1] +输出:0 ++ +
+ +
提示:
+ +n == nums.length
1 <= n <= 5000
-5000 <= nums[i] <= 5000
nums
原来是一个升序排序的数组,并进行了 1
至 n
次旋转+ +
进阶:
+ +给定一个无序的数组,找出数组在排序之后,相邻元素之间最大的差值。
+ +如果数组元素个数小于 2,则返回 0。
+ +示例 1:
+ +输入: [3,6,9,1] +输出: 3 +解释: 排序后的数组是 [1,3,6,9], 其中相邻元素 (3,6) 和 (6,9) 之间都存在最大差值 3。+ +
示例 2:
+ +输入: [10] +输出: 0 +解释: 数组元素个数小于 2,因此返回 0。+ +
说明:
+ +一些恶魔抓住了公主(P)并将她关在了地下城的右下角。地下城是由 M x N 个房间组成的二维网格。我们英勇的骑士(K)最初被安置在左上角的房间里,他必须穿过地下城并通过对抗恶魔来拯救公主。
+ +骑士的初始健康点数为一个正整数。如果他的健康点数在某一时刻降至 0 或以下,他会立即死亡。
+ +有些房间由恶魔守卫,因此骑士在进入这些房间时会失去健康点数(若房间里的值为负整数,则表示骑士将损失健康点数);其他房间要么是空的(房间里的值为 0),要么包含增加骑士健康点数的魔法球(若房间里的值为正整数,则表示骑士将增加健康点数)。
+ +为了尽快到达公主,骑士决定每次只向右或向下移动一步。
+ ++ +
编写一个函数来计算确保骑士能够拯救到公主所需的最低初始健康点数。
+ +例如,考虑到如下布局的地下城,如果骑士遵循最佳路径 右 -> 右 -> 下 -> 下
,则骑士的初始健康点数至少为 7。
-2 (K) | +-3 | +3 | +
-5 | +-10 | +1 | +
10 | +30 | +-5 (P) | +
+ +
说明:
+ +骑士的健康点数没有上限。
+给定一个整数数组 prices
,它的第 i
个元素 prices[i]
是一支给定的股票在第 i
天的价格。
设计一个算法来计算你所能获取的最大利润。你最多可以完成 k 笔交易。
+ +注意:你不能同时参与多笔交易(你必须在再次购买前出售掉之前的股票)。
+ ++ +
示例 1:
+ ++输入:k = 2, prices = [2,4,1] +输出:2 +解释:在第 1 天 (股票价格 = 2) 的时候买入,在第 2 天 (股票价格 = 4) 的时候卖出,这笔交易所能获得利润 = 4-2 = 2 。+ +
示例 2:
+ ++输入:k = 2, prices = [3,2,6,5,0,3] +输出:7 +解释:在第 2 天 (股票价格 = 2) 的时候买入,在第 3 天 (股票价格 = 6) 的时候卖出, 这笔交易所能获得利润 = 6-2 = 4 。 + 随后,在第 5 天 (股票价格 = 0) 的时候买入,在第 6 天 (股票价格 = 3) 的时候卖出, 这笔交易所能获得利润 = 3-0 = 3 。+ +
+ +
提示:
+ +0 <= k <= 100
0 <= prices.length <= 1000
0 <= prices[i] <= 1000
给定一个 m x n
二维字符网格 board
和一个单词(字符串)列表 words
,找出所有同时在二维网格和字典中出现的单词。
单词必须按照字母顺序,通过 相邻的单元格 内的字母构成,其中“相邻”单元格是那些水平相邻或垂直相邻的单元格。同一个单元格内的字母在一个单词中不允许被重复使用。
+ ++ +
示例 1:
+ ++输入:board = [["o","a","a","n"],["e","t","a","e"],["i","h","k","r"],["i","f","l","v"]], words = ["oath","pea","eat","rain"] +输出:["eat","oath"] ++ +
示例 2:
+ ++输入:board = [["a","b"],["c","d"]], words = ["abcb"] +输出:[] ++ +
+ +
提示:
+ +m == board.length
n == board[i].length
1 <= m, n <= 12
board[i][j]
是一个小写英文字母1 <= words.length <= 3 * 104
1 <= words[i].length <= 10
words[i]
由小写英文字母组成words
中的所有字符串互不相同给定一个字符串 s,你可以通过在字符串前面添加字符将其转换为回文串。找到并返回可以用这种方式转换的最短回文串。
+ ++ +
示例 1:
+ ++输入:s = "aacecaaa" +输出:"aaacecaaa" ++ +
示例 2:
+ ++输入:s = "abcd" +输出:"dcbabcd" ++ +
+ +
提示:
+ +0 <= s.length <= 5 * 104
s
仅由小写英文字母组成城市的天际线是从远处观看该城市中所有建筑物形成的轮廓的外部轮廓。给你所有建筑物的位置和高度,请返回由这些建筑物形成的 天际线 。
+ +每个建筑物的几何信息由数组 buildings
表示,其中三元组 buildings[i] = [lefti, righti, heighti]
表示:
lefti
是第 i
座建筑物左边缘的 x
坐标。righti
是第 i
座建筑物右边缘的 x
坐标。heighti
是第 i
座建筑物的高度。天际线 应该表示为由 “关键点” 组成的列表,格式 [[x1,y1],[x2,y2],...]
,并按 x 坐标 进行 排序 。关键点是水平线段的左端点。列表中最后一个点是最右侧建筑物的终点,y
坐标始终为 0
,仅用于标记天际线的终点。此外,任何两个相邻建筑物之间的地面都应被视为天际线轮廓的一部分。
注意:输出天际线中不得有连续的相同高度的水平线。例如 [...[2 3], [4 5], [7 5], [11 5], [12 7]...]
是不正确的答案;三条高度为 5 的线应该在最终输出中合并为一个:[...[2 3], [4 5], [12 7], ...]
+ +
示例 1:
+ ++输入:buildings = [[2,9,10],[3,7,15],[5,12,12],[15,20,10],[19,24,8]] +输出:[[2,10],[3,15],[7,12],[12,0],[15,10],[20,8],[24,0]] +解释: +图 A 显示输入的所有建筑物的位置和高度, +图 B 显示由这些建筑物形成的天际线。图 B 中的红点表示输出列表中的关键点。+ +
示例 2:
+ ++输入:buildings = [[0,2,3],[2,5,3]] +输出:[[0,3],[5,0]] ++ +
+ +
提示:
+ +1 <= buildings.length <= 104
0 <= lefti < righti <= 231 - 1
1 <= heighti <= 231 - 1
buildings
按 lefti
非递减排序给你一个字符串表达式 s
,请你实现一个基本计算器来计算并返回它的值。
+ +
示例 1:
+ ++输入:s = "1 + 1" +输出:2 ++ +
示例 2:
+ ++输入:s = " 2-1 + 2 " +输出:3 ++ +
示例 3:
+ ++输入:s = "(1+(4+5+2)-3)+(6+8)" +输出:23 ++ +
+ +
提示:
+ +1 <= s.length <= 3 * 105
s
由数字、'+'
、'-'
、'('
、')'
、和 ' '
组成s
表示一个有效的表达式给定一个整数 n
,计算所有小于等于 n
的非负整数中数字 1
出现的个数。
+ +
示例 1:
+ ++输入:n = 13 +输出:6 ++ +
示例 2:
+ ++输入:n = 0 +输出:0 ++ +
+ +
提示:
+ +0 <= n <= 109
给你一个整数数组 nums
,有一个大小为 k
的滑动窗口从数组的最左侧移动到数组的最右侧。你只可以看到在滑动窗口内的 k
个数字。滑动窗口每次只向右移动一位。
返回滑动窗口中的最大值。
+ ++ +
示例 1:
+ ++输入:nums = [1,3,-1,-3,5,3,6,7], k = 3 +输出:[3,3,5,5,6,7] +解释: +滑动窗口的位置 最大值 +--------------- ----- +[1 3 -1] -3 5 3 6 7 3 + 1 [3 -1 -3] 5 3 6 7 3 + 1 3 [-1 -3 5] 3 6 7 5 + 1 3 -1 [-3 5 3] 6 7 5 + 1 3 -1 -3 [5 3 6] 7 6 + 1 3 -1 -3 5 [3 6 7] 7 ++ +
示例 2:
+ ++输入:nums = [1], k = 1 +输出:[1] ++ +
示例 3:
+ ++输入:nums = [1,-1], k = 1 +输出:[1,-1] ++ +
示例 4:
+ ++输入:nums = [9,11], k = 2 +输出:[11] ++ +
示例 5:
+ ++输入:nums = [4,-2], k = 2 +输出:[4]+ +
+ +
提示:
+ +1 <= nums.length <= 105
-104 <= nums[i] <= 104
1 <= k <= nums.length
将非负整数 num
转换为其对应的英文表示。
+ +
示例 1:
+ ++输入:num = 123 +输出:"One Hundred Twenty Three" ++ +
示例 2:
+ ++输入:num = 12345 +输出:"Twelve Thousand Three Hundred Forty Five" ++ +
示例 3:
+ ++输入:num = 1234567 +输出:"One Million Two Hundred Thirty Four Thousand Five Hundred Sixty Seven" ++ +
示例 4:
+ ++输入:num = 1234567891 +输出:"One Billion Two Hundred Thirty Four Million Five Hundred Sixty Seven Thousand Eight Hundred Ninety One" ++ +
+ +
提示:
+ +0 <= num <= 231 - 1
给定一个仅包含数字 0-9
的字符串 num
和一个目标值整数 target
,在 num
的数字之间添加 二元 运算符(不是一元)+
、-
或 *
,返回所有能够得到目标值的表达式。
+ +
示例 1:
+ +
+输入: num =
"123", target = 6
+输出: ["1+2+3", "1*2*3"]
+
+
+示例 2:
+ +
+输入: num =
"232", target = 8
+输出: ["2*3+2", "2+3*2"]
+
+示例 3:
+ +
+输入: num =
"105", target = 5
+输出: ["1*0+5","10-5"]
+
+示例 4:
+ +
+输入: num =
"00", target = 0
+输出: ["0+0", "0-0", "0*0"]
+
+
+示例 5:
+ +
+输入: num =
"3456237490", target = 9191
+输出: []
+
++ +
提示:
+ +1 <= num.length <= 10
num
仅含数字-231 <= target <= 231 - 1
中位数是有序列表中间的数。如果列表长度是偶数,中位数则是中间两个数的平均值。
+ +例如,
+ +[2,3,4] 的中位数是 3
+ +[2,3] 的中位数是 (2 + 3) / 2 = 2.5
+ +设计一个支持以下两种操作的数据结构:
+ +示例:
+ +addNum(1) +addNum(2) +findMedian() -> 1.5 +addNum(3) +findMedian() -> 2+ +
进阶:
+ +序列化是将一个数据结构或者对象转换为连续的比特位的操作,进而可以将转换后的数据存储在一个文件或者内存中,同时也可以通过网络传输到另一个计算机环境,采取相反方式重构得到原数据。
+ +请设计一个算法来实现二叉树的序列化与反序列化。这里不限定你的序列 / 反序列化算法执行逻辑,你只需要保证一个二叉树可以被序列化为一个字符串并且将这个字符串反序列化为原始的树结构。
+ +提示: 输入输出格式与 LeetCode 目前使用的方式一致,详情请参阅 LeetCode 序列化二叉树的格式。你并非必须采取这种方式,你也可以采用其他的方法解决这个问题。
+ ++ +
示例 1:
+ ++输入:root = [1,2,3,null,null,4,5] +输出:[1,2,3,null,null,4,5] ++ +
示例 2:
+ ++输入:root = [] +输出:[] ++ +
示例 3:
+ ++输入:root = [1] +输出:[1] ++ +
示例 4:
+ ++输入:root = [1,2] +输出:[1,2] ++ +
+ +
提示:
+ +[0, 104]
内-1000 <= Node.val <= 1000
给你一个由若干括号和字母组成的字符串 s
,删除最小数量的无效括号,使得输入的字符串有效。
返回所有可能的结果。答案可以按 任意顺序 返回。
+ ++ +
示例 1:
+ ++输入:s = "()())()" +输出:["(())()","()()()"] ++ +
示例 2:
+ ++输入:s = "(a)())()" +输出:["(a())()","(a)()()"] ++ +
示例 3:
+ ++输入:s = ")(" +输出:[""] ++ +
+ +
提示:
+ +1 <= s.length <= 25
s
由小写英文字母以及括号 '('
和 ')'
组成s
中至多含 20
个括号有 n
个气球,编号为0
到 n - 1
,每个气球上都标有一个数字,这些数字存在数组 nums
中。
现在要求你戳破所有的气球。戳破第 i
个气球,你可以获得 nums[i - 1] * nums[i] * nums[i + 1]
枚硬币。 这里的 i - 1
和 i + 1
代表和 i
相邻的两个气球的序号。如果 i - 1
或 i + 1
超出了数组的边界,那么就当它是一个数字为 1
的气球。
求所能获得硬币的最大数量。
+ ++示例 1: + +
+输入:nums = [3,1,5,8] +输出:167 +解释: +nums = [3,1,5,8] --> [3,5,8] --> [3,8] --> [8] --> [] +coins = 3*1*5 + 3*5*8 + 1*3*8 + 1*8*1 = 167+ +
示例 2:
+ ++输入:nums = [1,5] +输出:10 ++ +
+ +
提示:
+ +n == nums.length
1 <= n <= 500
0 <= nums[i] <= 100
给你`一个整数数组 nums
,按要求返回一个新数组 counts
。数组 counts
有该性质: counts[i]
的值是 nums[i]
右侧小于 nums[i]
的元素的数量。
+ +
示例 1:
+ +
+输入:nums = [5,2,6,1]
+输出:[2,1,1,0]
+解释:
+5 的右侧有 2 个更小的元素 (2 和 1)
+2 的右侧仅有 1 个更小的元素 (1)
+6 的右侧有 1 个更小的元素 (1)
+1 的右侧有 0 个更小的元素
+
+
+示例 2:
+ ++输入:nums = [-1] +输出:[0] ++ +
示例 3:
+ ++输入:nums = [-1,-1] +输出:[0,0] ++ +
+ +
提示:
+ +1 <= nums.length <= 105
-104 <= nums[i] <= 104
给定长度分别为 m
和 n
的两个数组,其元素由 0-9
构成,表示两个自然数各位上的数字。现在从这两个数组中选出 k (k <= m + n)
个数字拼接成一个新的数,要求从同一个数组中取出的数字保持其在原数组中的相对顺序。
求满足该条件的最大数。结果返回一个表示该最大数的长度为 k
的数组。
说明: 请尽可能地优化你算法的时间和空间复杂度。
+ +示例 1:
+ +输入: +nums1 =+ +[3, 4, 6, 5]
+nums2 =[9, 1, 2, 5, 8, 3]
+k =5
+输出: +[9, 8, 6, 5, 3]
示例 2:
+ +输入: +nums1 =+ +[6, 7]
+nums2 =[6, 0, 4]
+k =5
+输出: +[6, 7, 6, 0, 4]
示例 3:
+ +输入: +nums1 =+ + +## template + +```python + +class Solution: + def maxNumber(self, nums1: List[int], nums2: List[int], k: int) -> List[int]: + def pick_max(nums, k): + stack = [] + drop = len(nums) - k + for num in nums: + while drop and stack and stack[-1] < num: + stack.pop() + drop -= 1 + stack.append(num) + return stack[:k] + + def merge(A, B): + lst = [] + while A or B: + bigger = A if A > B else B + lst.append(bigger[0]) + bigger.pop(0) + return lst + + return max( + merge(pick_max(nums1, i), pick_max(nums2, k - i)) + for i in range(k + 1) + if i <= len(nums1) and k - i <= len(nums2) + ) +``` + +## 答案 + +```python + +``` + +## 选项 + +### A + +```python + +``` + +### B + +```python + +``` + +### C + +```python + +``` \ No newline at end of file diff --git "a/data/3.dailycode\351\253\230\351\230\266/3.python/327.exercises/config.json" "b/data/3.dailycode\351\253\230\351\230\266/3.python/327.exercises/config.json" new file mode 100644 index 00000000..959ecb32 --- /dev/null +++ "b/data/3.dailycode\351\253\230\351\230\266/3.python/327.exercises/config.json" @@ -0,0 +1,10 @@ +{ + "node_id": "dailycode-cb69b420425f4a989878a984d31703eb", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [], + "export": [ + "solution.json" + ] +} \ No newline at end of file diff --git "a/data/3.dailycode\351\253\230\351\230\266/3.python/327.exercises/solution.json" "b/data/3.dailycode\351\253\230\351\230\266/3.python/327.exercises/solution.json" new file mode 100644 index 00000000..0153ce59 --- /dev/null +++ "b/data/3.dailycode\351\253\230\351\230\266/3.python/327.exercises/solution.json" @@ -0,0 +1,7 @@ +{ + "type": "code_options", + "source": "solution.md", + "exercise_id": "a9f7e57050c1400588485673f78712b3", + "author": "csdn.net", + "keywords": "树状数组,线段树,数组,二分查找,分治,有序集合,归并排序" +} \ No newline at end of file diff --git "a/data/3.dailycode\351\253\230\351\230\266/3.python/327.exercises/solution.md" "b/data/3.dailycode\351\253\230\351\230\266/3.python/327.exercises/solution.md" new file mode 100644 index 00000000..bc77c49a --- /dev/null +++ "b/data/3.dailycode\351\253\230\351\230\266/3.python/327.exercises/solution.md" @@ -0,0 +1,118 @@ +# 区间和的个数 + +[3, 9]
+nums2 =[8, 9]
+k =3
+输出: +[9, 8, 9]
给你一个整数数组 nums
以及两个整数 lower
和 upper
。求数组中,值位于范围 [lower, upper]
(包含 lower
和 upper
)之内的 区间和的个数 。
区间和 S(i, j)
表示在 nums
中,位置从 i
到 j
的元素之和,包含 i
和 j
(i
≤ j
)。
+示例 1: + +
+输入:nums = [-2,5,-1], lower = -2, upper = 2 +输出:3 +解释:存在三个区间:[0,0]、[2,2] 和 [0,2] ,对应的区间和分别是:-2 、-1 、2 。 ++ +
示例 2:
+ ++输入:nums = [0], lower = 0, upper = 0 +输出:1 ++ +
+ +
提示:
+ +1 <= nums.length <= 105
-231 <= nums[i] <= 231 - 1
-105 <= lower <= upper <= 105
给定一个 m x n
整数矩阵 matrix
,找出其中 最长递增路径 的长度。
对于每个单元格,你可以往上,下,左,右四个方向移动。 你 不能 在 对角线 方向上移动或移动到 边界外(即不允许环绕)。
+ ++ +
示例 1:
+ +
+输入:matrix = [[9,9,4],[6,6,8],[2,1,1]]
+输出:4
+解释:最长递增路径为 [1, 2, 6, 9]
。
+
+示例 2:
+ +
+输入:matrix = [[3,4,5],[3,2,6],[2,2,1]]
+输出:4
+解释:最长递增路径是 [3, 4, 5, 6]
。注意不允许在对角线方向上移动。
+
+
+示例 3:
+ ++输入:matrix = [[1]] +输出:1 ++ +
+ +
提示:
+ +m == matrix.length
n == matrix[i].length
1 <= m, n <= 200
0 <= matrix[i][j] <= 231 - 1
[1, n]
区间内选取任意个数字补充到 nums 中,使得 [1, n]
区间内的任何数字都可以用 nums 中某几个数字的和来表示。请输出满足上述要求的最少需要补充的数字个数。
+
+示例 1:
+ +输入: nums =+ +[1,3]
, n =6
+输出: 1 +解释: +根据 nums 里现有的组合[1], [3], [1,3]
,可以得出1, 3, 4
。 +现在如果我们将2
添加到 nums 中, 组合变为:[1], [2], [3], [1,3], [2,3], [1,2,3]
。 +其和可以表示数字1, 2, 3, 4, 5, 6
,能够覆盖[1, 6]
区间里所有的数。 +所以我们最少需要添加一个数字。
示例 2:
+ +输入: nums =+ +[1,5,10]
, n =20
+输出: 2 +解释: 我们需要添加[2, 4]
。 +
示例 3:
+ +输入: nums =+ + +## template + +```python + +class Solution: + def minPatches(self, nums: List[int], n: int) -> int: + count = 0 + miss = 1 + idx = 0 + while miss <= n: + if idx < len(nums) and nums[idx] <= miss: + miss += nums[idx] + idx += 1 + else: + count += 1 + miss += miss + return count + + +``` + +## 答案 + +```python + +``` + +## 选项 + +### A + +```python + +``` + +### B + +```python + +``` + +### C + +```python + +``` \ No newline at end of file diff --git "a/data/3.dailycode\351\253\230\351\230\266/3.python/335.exercises/config.json" "b/data/3.dailycode\351\253\230\351\230\266/3.python/335.exercises/config.json" new file mode 100644 index 00000000..81b1708f --- /dev/null +++ "b/data/3.dailycode\351\253\230\351\230\266/3.python/335.exercises/config.json" @@ -0,0 +1,10 @@ +{ + "node_id": "dailycode-ec344b2a5bb142379e0e19b8a34a7831", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [], + "export": [ + "solution.json" + ] +} \ No newline at end of file diff --git "a/data/3.dailycode\351\253\230\351\230\266/3.python/335.exercises/solution.json" "b/data/3.dailycode\351\253\230\351\230\266/3.python/335.exercises/solution.json" new file mode 100644 index 00000000..1ae5da2c --- /dev/null +++ "b/data/3.dailycode\351\253\230\351\230\266/3.python/335.exercises/solution.json" @@ -0,0 +1,7 @@ +{ + "type": "code_options", + "source": "solution.md", + "exercise_id": "ad9aad91b74c4ce889128bfdc4493b9f", + "author": "csdn.net", + "keywords": "几何,数组,数学" +} \ No newline at end of file diff --git "a/data/3.dailycode\351\253\230\351\230\266/3.python/335.exercises/solution.md" "b/data/3.dailycode\351\253\230\351\230\266/3.python/335.exercises/solution.md" new file mode 100644 index 00000000..5aa71cb5 --- /dev/null +++ "b/data/3.dailycode\351\253\230\351\230\266/3.python/335.exercises/solution.md" @@ -0,0 +1,83 @@ +# 路径交叉 + +[1,2,2]
, n =5
+输出: 0 +
给你一个整数数组 distance
。
从 X-Y 平面上的点 (0,0)
开始,先向北移动 distance[0]
米,然后向西移动 distance[1]
米,向南移动 distance[2]
米,向东移动 distance[3]
米,持续移动。也就是说,每次移动后你的方位会发生逆时针变化。
判断你所经过的路径是否相交。如果相交,返回 true
;否则,返回 false
。
+ +
示例 1:
+ ++输入:distance = [2,1,1,2] +输出:true ++ +
示例 2:
+ ++输入:distance = [1,2,3,4] +输出:false ++ +
示例 3:
+ ++输入:distance = [1,1,1,1] +输出:true+ +
+ +
提示:
+ +1 <= distance.length <= 105
1 <= distance[i] <= 105
给定一组 互不相同 的单词, 找出所有 不同 的索引对 (i, j)
,使得列表中的两个单词, words[i] + words[j]
,可拼接成回文串。
+ +
示例 1:
+ +
+输入:words = ["abcd","dcba","lls","s","sssll"]
+输出:[[0,1],[1,0],[3,2],[2,4]]
+解释:可拼接成的回文串为 ["dcbaabcd","abcddcba","slls","llssssll"]
+
+
+示例 2:
+ +
+输入:words = ["bat","tab","cat"]
+输出:[[0,1],[1,0]]
+解释:可拼接成的回文串为 ["battab","tabbat"]
+
+示例 3:
+ ++输入:words = ["a",""] +输出:[[0,1],[1,0]] ++ + +
提示:
+ +1 <= words.length <= 5000
0 <= words[i].length <= 300
words[i]
由小写英文字母组成 给你一个由非负整数 a1, a2, ..., an
组成的数据流输入,请你将到目前为止看到的数字总结为不相交的区间列表。
实现 SummaryRanges
类:
SummaryRanges()
使用一个空数据流初始化对象。void addNum(int val)
向数据流中加入整数 val
。int[][] getIntervals()
以不相交区间 [starti, endi]
的列表形式返回对数据流中整数的总结。+ +
示例:
+ ++输入: +["SummaryRanges", "addNum", "getIntervals", "addNum", "getIntervals", "addNum", "getIntervals", "addNum", "getIntervals", "addNum", "getIntervals"] +[[], [1], [], [3], [], [7], [], [2], [], [6], []] +输出: +[null, null, [[1, 1]], null, [[1, 1], [3, 3]], null, [[1, 1], [3, 3], [7, 7]], null, [[1, 3], [7, 7]], null, [[1, 3], [6, 7]]] + +解释: +SummaryRanges summaryRanges = new SummaryRanges(); +summaryRanges.addNum(1); // arr = [1] +summaryRanges.getIntervals(); // 返回 [[1, 1]] +summaryRanges.addNum(3); // arr = [1, 3] +summaryRanges.getIntervals(); // 返回 [[1, 1], [3, 3]] +summaryRanges.addNum(7); // arr = [1, 3, 7] +summaryRanges.getIntervals(); // 返回 [[1, 1], [3, 3], [7, 7]] +summaryRanges.addNum(2); // arr = [1, 2, 3, 7] +summaryRanges.getIntervals(); // 返回 [[1, 3], [7, 7]] +summaryRanges.addNum(6); // arr = [1, 2, 3, 6, 7] +summaryRanges.getIntervals(); // 返回 [[1, 3], [6, 7]] ++ +
+ +
提示:
+ +0 <= val <= 104
addNum
和 getIntervals
方法 3 * 104
次+ +
进阶:如果存在大量合并,并且与数据流的大小相比,不相交区间的数量很小,该怎么办?
+ + +## template + +```python + +class SummaryRanges: + def __init__(self): + self.rec = set() + + self.s = list() + + def binarySearch_l(self, x: int): + s = self.s + l, r = 0, len(s) - 1 + while l < r: + mid = l + r >> 1 + if s[mid][0] >= x: + r = mid + else: + l = mid + 1 + return l + + def binarySearch(self, x: int): + s = self.s + l, r = 0, len(s) - 1 + while l < r: + mid = l + r >> 1 + if s[mid][1] >= x: + r = mid + else: + l = mid + 1 + return l + + def addNum(self, val: int) -> None: + rec, s = self.rec, self.s + if val in rec: + return + else: + + if val - 1 not in rec and val + 1 not in rec: + + s.append([val, val]) + s.sort() + elif val - 1 in rec and val + 1 not in rec: + + p = self.binarySearch(val - 1) + s[p][1] = val + elif val - 1 not in rec and val + 1 in rec: + + p = self.binarySearch_l(val + 1) + s[p][0] = val + else: + + p = self.binarySearch(val) + s[p - 1][1] = s[p][1] + + s.pop(p) + rec.add(val) + + def getIntervals(self) -> List[List[int]]: + return self.s + +``` + +## 答案 + +```python + +``` + +## 选项 + +### A + +```python + +``` + +### B + +```python + +``` + +### C + +```python + +``` \ No newline at end of file diff --git "a/data/3.dailycode\351\253\230\351\230\266/3.python/354.exercises/config.json" "b/data/3.dailycode\351\253\230\351\230\266/3.python/354.exercises/config.json" new file mode 100644 index 00000000..82fccd5f --- /dev/null +++ "b/data/3.dailycode\351\253\230\351\230\266/3.python/354.exercises/config.json" @@ -0,0 +1,10 @@ +{ + "node_id": "dailycode-4f5090940591403ca172ef548aca00e6", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [], + "export": [ + "solution.json" + ] +} \ No newline at end of file diff --git "a/data/3.dailycode\351\253\230\351\230\266/3.python/354.exercises/solution.json" "b/data/3.dailycode\351\253\230\351\230\266/3.python/354.exercises/solution.json" new file mode 100644 index 00000000..87444c4f --- /dev/null +++ "b/data/3.dailycode\351\253\230\351\230\266/3.python/354.exercises/solution.json" @@ -0,0 +1,7 @@ +{ + "type": "code_options", + "source": "solution.md", + "exercise_id": "15a847964c244a82ad1fb736d864210a", + "author": "csdn.net", + "keywords": "数组,二分查找,动态规划,排序" +} \ No newline at end of file diff --git "a/data/3.dailycode\351\253\230\351\230\266/3.python/354.exercises/solution.md" "b/data/3.dailycode\351\253\230\351\230\266/3.python/354.exercises/solution.md" new file mode 100644 index 00000000..ecef139e --- /dev/null +++ "b/data/3.dailycode\351\253\230\351\230\266/3.python/354.exercises/solution.md" @@ -0,0 +1,85 @@ +# 俄罗斯套娃信封问题 + +给你一个二维整数数组 envelopes
,其中 envelopes[i] = [wi, hi]
,表示第 i
个信封的宽度和高度。
当另一个信封的宽度和高度都比这个信封大的时候,这个信封就可以放进另一个信封里,如同俄罗斯套娃一样。
+ +请计算 最多能有多少个 信封能组成一组“俄罗斯套娃”信封(即可以把一个信封放到另一个信封里面)。
+ +注意:不允许旋转信封。
+ + +示例 1:
+ +
+输入:envelopes = [[5,4],[6,4],[6,7],[2,3]]
+输出:3
+解释:最多信封的个数为 3, 组合为:
[2,3] => [5,4] => [6,7]。
+
+示例 2:
+ ++输入:envelopes = [[1,1],[1,1],[1,1]] +输出:1 ++ +
+ +
提示:
+ +1 <= envelopes.length <= 5000
envelopes[i].length == 2
1 <= wi, hi <= 104
给你一个 m x n
的矩阵 matrix
和一个整数 k
,找出并返回矩阵内部矩形区域的不超过 k
的最大数值和。
题目数据保证总会存在一个数值和不超过 k
的矩形区域。
+ +
示例 1:
+ +
+输入:matrix = [[1,0,1],[0,-2,3]], k = 2
+输出:2
+解释:蓝色边框圈出来的矩形区域 [[0, 1], [-2, 3]]
的数值和是 2,且 2 是不超过 k 的最大数字(k = 2)。
+
+
+示例 2:
+ ++输入:matrix = [[2,2,-1]], k = 3 +输出:3 ++ +
+ +
提示:
+ +m == matrix.length
n == matrix[i].length
1 <= m, n <= 100
-100 <= matrix[i][j] <= 100
-105 <= k <= 105
+ +
进阶:如果行数远大于列数,该如何设计解决方案?
+ + +## template + +```python +import bisect + +class Solution: + def maxSumSubmatrix(self, matrix: List[List[int]], k: int) -> int: + m = len(matrix) + Row, Col = len(matrix), len(matrix[0]) + res = float("-inf") + for ru in range(Row): + col_sum = [0 for _ in range(Col)] + for rd in range(ru, Row): + for c in range(Col): + if matrix[rd][c] == k: + return k + col_sum[c] += matrix[rd][c] + + presum = [0] + cur_sum = 0 + for colsum in col_sum: + cur_sum += colsum + idx = bisect.bisect_left(presum, cur_sum - k) + if idx < len(presum): + res = max(res, cur_sum - presum[idx]) + if res == k: + return k + bisect.insort(presum, cur_sum) + + return res +``` + +## 答案 + +```python + +``` + +## 选项 + +### A + +```python + +``` + +### B + +```python + +``` + +### C + +```python + +``` \ No newline at end of file diff --git "a/data/3.dailycode\351\253\230\351\230\266/3.python/381.exercises/config.json" "b/data/3.dailycode\351\253\230\351\230\266/3.python/381.exercises/config.json" new file mode 100644 index 00000000..e9d8c6d3 --- /dev/null +++ "b/data/3.dailycode\351\253\230\351\230\266/3.python/381.exercises/config.json" @@ -0,0 +1,10 @@ +{ + "node_id": "dailycode-2bc30335c35f434fba906bd79c9d6052", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [], + "export": [ + "solution.json" + ] +} \ No newline at end of file diff --git "a/data/3.dailycode\351\253\230\351\230\266/3.python/381.exercises/solution.json" "b/data/3.dailycode\351\253\230\351\230\266/3.python/381.exercises/solution.json" new file mode 100644 index 00000000..483d16e8 --- /dev/null +++ "b/data/3.dailycode\351\253\230\351\230\266/3.python/381.exercises/solution.json" @@ -0,0 +1,7 @@ +{ + "type": "code_options", + "source": "solution.md", + "exercise_id": "e9e727954d394c91b956823f1d3af22d", + "author": "csdn.net", + "keywords": "设计,数组,哈希表,数学,随机化" +} \ No newline at end of file diff --git "a/data/3.dailycode\351\253\230\351\230\266/3.python/381.exercises/solution.md" "b/data/3.dailycode\351\253\230\351\230\266/3.python/381.exercises/solution.md" new file mode 100644 index 00000000..4cdc7460 --- /dev/null +++ "b/data/3.dailycode\351\253\230\351\230\266/3.python/381.exercises/solution.md" @@ -0,0 +1,106 @@ +# O(1) 时间插入、删除和获取随机元素 + +设计一个支持在平均 时间复杂度 O(1) 下, 执行以下操作的数据结构。
+ +注意: 允许出现重复元素。
+ +insert(val)
:向集合中插入元素 val。remove(val)
:当 val 存在时,从集合中移除一个 val。getRandom
:从现有集合中随机获取一个元素。每个元素被返回的概率应该与其在集合中的数量呈线性相关。示例:
+ +// 初始化一个空的集合。 +RandomizedCollection collection = new RandomizedCollection(); + +// 向集合中插入 1 。返回 true 表示集合不包含 1 。 +collection.insert(1); + +// 向集合中插入另一个 1 。返回 false 表示集合包含 1 。集合现在包含 [1,1] 。 +collection.insert(1); + +// 向集合中插入 2 ,返回 true 。集合现在包含 [1,1,2] 。 +collection.insert(2); + +// getRandom 应当有 2/3 的概率返回 1 ,1/3 的概率返回 2 。 +collection.getRandom(); + +// 从集合中删除 1 ,返回 true 。集合现在包含 [1,2] 。 +collection.remove(1); + +// getRandom 应有相同概率返回 1 和 2 。 +collection.getRandom(); ++ + +## template + +```python +class RandomizedSet: + def __init__(self): + """ + Initialize your data structure here. + """ + self.dict = {} + self.list = [] + + def insert(self, val: int) -> bool: + """ + Inserts a value to the set. Returns true if the set did not already contain the specified element. + """ + if val in self.dict: + return False + self.dict[val] = len(self.list) + self.list.append(val) + return True + + def remove(self, val: int) -> bool: + """ + Removes a value from the set. Returns true if the set contained the specified element. + """ + if val in self.dict: + + last_element, idx = self.list[-1], self.dict[val] + self.list[idx], self.dict[last_element] = last_element, idx + + self.list.pop() + del self.dict[val] + return True + return False + + def getRandom(self) -> int: + """ + Get a random element from the set. + """ + return choice(self.list) + + +``` + +## 答案 + +```python + +``` + +## 选项 + +### A + +```python + +``` + +### B + +```python + +``` + +### C + +```python + +``` \ No newline at end of file diff --git "a/data_source/exercises/\344\270\255\347\255\211/python/102.exercises/solution.md" "b/data_source/exercises/\344\270\255\347\255\211/python/102.exercises/solution.md" index 6bd85c7c..f3271d98 100644 --- "a/data_source/exercises/\344\270\255\347\255\211/python/102.exercises/solution.md" +++ "b/data_source/exercises/\344\270\255\347\255\211/python/102.exercises/solution.md" @@ -29,7 +29,34 @@ ## template ```python - +class TreeNode: + def __init__(self, x): + self.val = x + self.left = None + self.right = None + +class Solution(object): + def levelOrder(self, root): + """ + :type root: TreeNode + :rtype: List[List[int]] + """ + if not root: + return [] + + queue, res = [root], [] + while queue: + size = len(queue) + temp = [] + for i in range(size): + data = queue.pop(0) + temp.append(data.val) + if data.left: + queue.append(data.left) + if data.right: + queue.append(data.right) + res.append(temp) + return res ``` diff --git "a/data_source/exercises/\344\270\255\347\255\211/python/103.exercises/solution.md" "b/data_source/exercises/\344\270\255\347\255\211/python/103.exercises/solution.md" index dba7400d..77170350 100644 --- "a/data_source/exercises/\344\270\255\347\255\211/python/103.exercises/solution.md" +++ "b/data_source/exercises/\344\270\255\347\255\211/python/103.exercises/solution.md" @@ -27,8 +27,41 @@ ## template ```python - - +class TreeNode: + def __init__(self, x): + self.val = x + self.left = None + self.right = None + +class Solution: + def zigzagLevelOrder(self, root: TreeNode) -> List[List[int]]: + import collections + + if not root: + return [] + + res, q = [], collections.deque() + flag = False + q.append(root) + + while q: + temp = [] + flag = not flag + for _ in range(len(q)): + node = q.popleft() + + if flag: + temp.append(node.val) + + else: + temp.insert(0, node.val) + if node.left: + q.append(node.left) + if node.right: + q.append(node.right) + res.append(temp) + + return res ``` ## 答案 diff --git "a/data_source/exercises/\344\270\255\347\255\211/python/105.exercises/solution.md" "b/data_source/exercises/\344\270\255\347\255\211/python/105.exercises/solution.md" index 5520477f..202c59db 100644 --- "a/data_source/exercises/\344\270\255\347\255\211/python/105.exercises/solution.md" +++ "b/data_source/exercises/\344\270\255\347\255\211/python/105.exercises/solution.md" @@ -36,8 +36,21 @@ ## template ```python - - +class TreeNode: + def __init__(self, x): + self.val = x + self.left = None + self.right = None + +class Solution: + def buildTree(self, preorder, inorder): + if not preorder: + return None + root = TreeNode(preorder[0]) + i = inorder.index(root.val) + root.left = self.buildTree(preorder[1 : i + 1], inorder[:i]) + root.right = self.buildTree(preorder[i + 1 :], inorder[i + 1 :]) + return root ``` ## 答案 diff --git "a/data_source/exercises/\344\270\255\347\255\211/python/106.exercises/solution.md" "b/data_source/exercises/\344\270\255\347\255\211/python/106.exercises/solution.md" index d2e83ed8..c96ad100 100644 --- "a/data_source/exercises/\344\270\255\347\255\211/python/106.exercises/solution.md" +++ "b/data_source/exercises/\344\270\255\347\255\211/python/106.exercises/solution.md" @@ -24,6 +24,39 @@ ```python +class Solution: + def buildTree(self, inorder: List[int], postorder: List[int]) -> TreeNode: + def build_tree(in_left, in_right, post_left, post_right): + if in_left > in_right: + return + + post_root = post_right + + root = TreeNode(postorder[post_root]) + + in_root = inorder_map[root.val] + + size_of_left = in_root - in_left + + root.left = build_tree( + in_left, in_root - 1, post_left, post_left + size_of_left - 1 + ) + + root.right = build_tree( + in_root + 1, in_right, post_left + size_of_left, post_root - 1 + ) + + return root + + size = len(inorder) + + inorder_map = {} + + for i in range(size): + inorder_map[inorder[i]] = i + + return build_tree(0, size - 1, 0, size - 1) + ``` diff --git "a/data_source/exercises/\344\270\255\347\255\211/python/107.exercises/solution.md" "b/data_source/exercises/\344\270\255\347\255\211/python/107.exercises/solution.md" index 9fa8535b..e185a4da 100644 --- "a/data_source/exercises/\344\270\255\347\255\211/python/107.exercises/solution.md" +++ "b/data_source/exercises/\344\270\255\347\255\211/python/107.exercises/solution.md" @@ -28,7 +28,24 @@ ```python - +class Solution(object): + res = dict() + + def forwardSearch(self, root, depth): + if root != None: + if depth not in self.res.keys(): + self.res[depth] = [] + self.res[depth].append(root.val) + self.forwardSearch(root.left, depth + 1) + self.forwardSearch(root.right, depth + 1) + + def levelOrderBottom(self, root): + self.forwardSearch(root, 1) + result = [] + self.dic = dict() + for i in self.res.keys(): + result.append(self.res[i]) + return result[::-1] ``` ## 答案 diff --git "a/data_source/exercises/\344\270\255\347\255\211/python/109.exercises/solution.md" "b/data_source/exercises/\344\270\255\347\255\211/python/109.exercises/solution.md" index 22343e03..29ee3ae3 100644 --- "a/data_source/exercises/\344\270\255\347\255\211/python/109.exercises/solution.md" +++ "b/data_source/exercises/\344\270\255\347\255\211/python/109.exercises/solution.md" @@ -21,7 +21,44 @@ ## template ```python - +class TreeNode: + def __init__(self, x): + self.val = x + self.left = None + self.right = None + + +class ListNode: + def __init__(self, x): + self.val = x + self.next = None + + +class TreeNode(object): + def __init__(self, val=0, left=None, right=None): + self.val = val + self.left = left + self.right = right + + +class Solution: + def sortedListToBST(self, head: ListNode) -> TreeNode: + + arr = [] + cur = head + while cur: + arr.append(cur.val) + cur = cur.next + return self.dfs(arr) + + def dfs(self, arr): + if not arr: + return + m = len(arr) // 2 + root = TreeNode(arr[m]) + root.left = self.dfs(arr[:m]) + root.right = self.dfs(arr[m + 1 :]) + return root ``` diff --git "a/data_source/exercises/\344\270\255\347\255\211/python/113.exercises/solution.md" "b/data_source/exercises/\344\270\255\347\255\211/python/113.exercises/solution.md" index c1429145..dc71d015 100644 --- "a/data_source/exercises/\344\270\255\347\255\211/python/113.exercises/solution.md" +++ "b/data_source/exercises/\344\270\255\347\255\211/python/113.exercises/solution.md" @@ -46,6 +46,26 @@ ```python +class Solution: + def pathSum(self, root: TreeNode, sum: int) -> List[List[int]]: + pathvalue = 0 + path = [] + result = [] + + def preorder(node, pathvalue, sum, path, result): + if node == None: + return + pathvalue += node.val + path.append(node.val) + if pathvalue == sum and node.left == None and node.right == None: + result.append(list(path)) # 注意加list + preorder(node.left, pathvalue, sum, path, result) + preorder(node.right, pathvalue, sum, path, result) + pathvalue -= node.val + path.pop() + + preorder(root, pathvalue, sum, path, result) + return result ``` diff --git "a/data_source/exercises/\344\270\255\347\255\211/python/114.exercises/solution.md" "b/data_source/exercises/\344\270\255\347\255\211/python/114.exercises/solution.md" index 109ce00a..ba2c8f3e 100644 --- "a/data_source/exercises/\344\270\255\347\255\211/python/114.exercises/solution.md" +++ "b/data_source/exercises/\344\270\255\347\255\211/python/114.exercises/solution.md" @@ -48,6 +48,29 @@ ```python +class TreeNode(object): + def __init__(self, val=0, left=None, right=None): + self.val = val + self.left = left + self.right = right + + +class Solution: + def flatten(self, root: TreeNode) -> None: + """ + Do not return anything, modify root in-place instead. + """ + while root != None: + if root.left == None: + root = root.right + else: + pre = root.left + while pre.right != None: + pre = pre.right + pre.right = root.right + root.right = root.left + root.left = None + root = root.right ``` diff --git "a/data_source/exercises/\344\270\255\347\255\211/python/116.exercises/solution.md" "b/data_source/exercises/\344\270\255\347\255\211/python/116.exercises/solution.md" index 0f459805..3a4ad32c 100644 --- "a/data_source/exercises/\344\270\255\347\255\211/python/116.exercises/solution.md" +++ "b/data_source/exercises/\344\270\255\347\255\211/python/116.exercises/solution.md" @@ -48,7 +48,34 @@ struct Node { ## template ```python - +class Node(object): + def __init__(self, val, left, right, next): + self.val = val + self.left = left + self.right = right + self.next = next + + +class Solution(object): + def connect(self, root): + """ + :type root: Node + :rtype: Node + """ + if not root: + return + node = [root] + while node: + l = len(node) + for n in range(l): + cur = node.pop(0) + if n < (l - 1): + cur.next = node[0] + if cur.left: + node.append(cur.left) + if cur.right: + node.append(cur.right) + return root ``` diff --git "a/data_source/exercises/\344\270\255\347\255\211/python/117.exercises/solution.md" "b/data_source/exercises/\344\270\255\347\255\211/python/117.exercises/solution.md" index 3f514608..fb9c095a 100644 --- "a/data_source/exercises/\344\270\255\347\255\211/python/117.exercises/solution.md" +++ "b/data_source/exercises/\344\270\255\347\255\211/python/117.exercises/solution.md" @@ -52,6 +52,41 @@ struct Node { ## template ```python +class Node(object): + def __init__(self, val, left, right, next): + self.val = val + self.left = left + self.right = right + self.next = next + + +class Solution: + def connect(self, root: "Node") -> "Node": + if root == None: + return None + firstNode = root + while firstNode: + while firstNode and firstNode.left == None and firstNode.right == None: + firstNode = firstNode.next + + if firstNode == None: + break + cur = firstNode + pre = None + + while cur: + if cur.left: + if pre: + pre.next = cur.left + pre = cur.left + if cur.right: + if pre: + pre.next = cur.right + pre = cur.right + cur = cur.next + firstNode = firstNode.left if firstNode.left else firstNode.right + return root + ``` diff --git "a/data_source/exercises/\344\270\255\347\255\211/python/120.exercises/solution.md" "b/data_source/exercises/\344\270\255\347\255\211/python/120.exercises/solution.md" index 8a08afe2..f96d8eb4 100644 --- "a/data_source/exercises/\344\270\255\347\255\211/python/120.exercises/solution.md" +++ "b/data_source/exercises/\344\270\255\347\255\211/python/120.exercises/solution.md" @@ -50,6 +50,19 @@ ```python +class Solution(object): + def minimumTotal(self, triangle): + """ + :type triangle: List[List[int]] + :rtype: int + """ + n = len(triangle) + dp = triangle[-1] + for i in range(n - 2, -1, -1): + for j in range(i + 1): + dp[j] = triangle[i][j] + min(dp[j], dp[j + 1]) + print dp + return dp[0] ``` diff --git "a/data_source/exercises/\344\270\255\347\255\211/python/128.exercises/solution.md" "b/data_source/exercises/\344\270\255\347\255\211/python/128.exercises/solution.md" index 9bb347e0..c2ec4ab6 100644 --- "a/data_source/exercises/\344\270\255\347\255\211/python/128.exercises/solution.md" +++ "b/data_source/exercises/\344\270\255\347\255\211/python/128.exercises/solution.md" @@ -34,6 +34,29 @@ ```python +class Solution: + def longestConsecutive(self, nums: List[int]) -> int: + hash_dict = {} + + max_length = 0 + + for num in nums: + + if num not in hash_dict: + + pre_length = hash_dict.get(num - 1, 0) + next_length = hash_dict.get(num + 1, 0) + + cur_length = pre_length + 1 + next_length + + if cur_length > max_length: + max_length = cur_length + + hash_dict[num] = cur_length + hash_dict[num - pre_length] = cur_length + hash_dict[num + next_length] = cur_length + + return max_length ``` diff --git "a/data_source/exercises/\344\270\255\347\255\211/python/129.exercises/solution.md" "b/data_source/exercises/\344\270\255\347\255\211/python/129.exercises/solution.md" index b42a42b6..02536fe5 100644 --- "a/data_source/exercises/\344\270\255\347\255\211/python/129.exercises/solution.md" +++ "b/data_source/exercises/\344\270\255\347\255\211/python/129.exercises/solution.md" @@ -53,8 +53,25 @@ ## template ```python - - +class TreeNode: + def __init__(self, x): + self.val = x + self.left = None + self.right = None + +class Solution: + def sumNumbers(self, root: TreeNode) -> int: + def dfs(root: TreeNode, sumNumber: int) -> int: + if not root: + return 0 + tmpsum = sumNumber * 10 + root.val + + if not root.left and not root.right: + return tmpsum + else: + return dfs(root.left, tmpsum) + dfs(root.right, tmpsum) + + return dfs(root, 0) ``` ## 答案 diff --git "a/data_source/exercises/\344\270\255\347\255\211/python/130.exercises/solution.md" "b/data_source/exercises/\344\270\255\347\255\211/python/130.exercises/solution.md" index 6898f422..7b4cf36c 100644 --- "a/data_source/exercises/\344\270\255\347\255\211/python/130.exercises/solution.md" +++ "b/data_source/exercises/\344\270\255\347\255\211/python/130.exercises/solution.md" @@ -37,6 +37,50 @@ ## template ```python +class Solution: + def solve(self, board: List[List[str]]) -> None: + """ + Do not return anything, modify board in-place instead. + """ + if not board or len(board) == 0: + return + + m = len(board) + n = len(board[0]) + + from collections import deque + + queue = deque() + + for i in range(m): + + if board[i][0] == "O": + queue.append((i, 0)) + if board[i][n - 1] == "O": + queue.append((i, n - 1)) + + for j in range(n): + + if board[0][j] == "O": + queue.append((0, j)) + if board[m - 1][j] == "O": + queue.append((m - 1, j)) + + while queue: + x, y = queue.popleft() + board[x][y] = "M" + + for nx, ny in [(x - 1, y), (x + 1, y), (x, y - 1), (x, y + 1)]: + if 0 <= nx < m and 0 <= ny < n and board[nx][ny] == "O": + queue.append((nx, ny)) + + for i in range(m): + for j in range(n): + if board[i][j] == "O": + board[i][j] = "X" + if board[i][j] == "M": + board[i][j] = "O" + ``` diff --git "a/data_source/exercises/\344\270\255\347\255\211/python/131.exercises/solution.md" "b/data_source/exercises/\344\270\255\347\255\211/python/131.exercises/solution.md" index d55b476f..d7994fb6 100644 --- "a/data_source/exercises/\344\270\255\347\255\211/python/131.exercises/solution.md" +++ "b/data_source/exercises/\344\270\255\347\255\211/python/131.exercises/solution.md" @@ -33,6 +33,25 @@ ## template ```python +class Solution(object): + def partition(self, s): + """ + :type s: str + :rtype: List[List[str]] + """ + if len(s) == 0: + return [] + else: + res = [] + self.dividedAndsel(s, [], res) + return res + + def dividedAndsel(self, s, tmp, res): + if len(s) == 0: + res.append(tmp) + for i in range(1, len(s) + 1): + if s[:i] == s[:i][::-1]: + self.dividedAndsel(s[i:], tmp + [s[:i]], res) ``` diff --git "a/data_source/exercises/\344\270\255\347\255\211/python/133.exercises/solution.md" "b/data_source/exercises/\344\270\255\347\255\211/python/133.exercises/solution.md" index fbc9e348..1b6cbf56 100644 --- "a/data_source/exercises/\344\270\255\347\255\211/python/133.exercises/solution.md" +++ "b/data_source/exercises/\344\270\255\347\255\211/python/133.exercises/solution.md" @@ -74,6 +74,32 @@ ## template ```python +class Node: + def __init__(self, val=0, neighbors=[]): + self.val = val + self.neighbors = neighbors + + +class Solution: + def cloneGraph(self, node: "Node") -> "Node": + marked = {} + + def dfs(node): + if not node: + return node + + if node in marked: + return marked[node] + + clone_node = Node(node.val, []) + marked[node] = clone_node + + for neighbor in node.neighbors: + clone_node.neighbors.append(dfs(neighbor)) + + return clone_node + + return dfs(node) ``` diff --git "a/data_source/exercises/\344\270\255\347\255\211/python/134.exercises/solution.md" "b/data_source/exercises/\344\270\255\347\255\211/python/134.exercises/solution.md" index f004720e..d75f0389 100644 --- "a/data_source/exercises/\344\270\255\347\255\211/python/134.exercises/solution.md" +++ "b/data_source/exercises/\344\270\255\347\255\211/python/134.exercises/solution.md" @@ -51,6 +51,25 @@ cost = [3,4,3] ## template ```python +class Solution(object): + def canCompleteCircuit(self, gas, cost): + """ + :type gas: List[int] + :type cost: List[int] + :rtype: int + """ + n = len(gas) + if sum(gas) < sum(cost): + return -1 + else: + start = 0 + path = 0 + for i in range(n): + path = path + (gas[i] - cost[i]) + if path < 0: + start = i + 1 + path = 0 + return start ``` diff --git "a/data_source/exercises/\344\270\255\347\255\211/python/137.exercises/solution.md" "b/data_source/exercises/\344\270\255\347\255\211/python/137.exercises/solution.md" index da24fefd..8bb220de 100644 --- "a/data_source/exercises/\344\270\255\347\255\211/python/137.exercises/solution.md" +++ "b/data_source/exercises/\344\270\255\347\255\211/python/137.exercises/solution.md" @@ -37,6 +37,18 @@ ```python +class Solution(object): + def singleNumber(self, nums): + """ + :type nums: List[int] + :rtype: int + """ + a = 0 + b = 0 + for num in nums: + a = (num ^ a) & ~b + b = (num ^ b) & ~a + return a ``` diff --git "a/data_source/exercises/\344\270\255\347\255\211/python/138.exercises/solution.md" "b/data_source/exercises/\344\270\255\347\255\211/python/138.exercises/solution.md" index f7ad177b..258d3d65 100644 --- "a/data_source/exercises/\344\270\255\347\255\211/python/138.exercises/solution.md" +++ "b/data_source/exercises/\344\270\255\347\255\211/python/138.exercises/solution.md" @@ -68,6 +68,34 @@ ## template ```python +class Node(object): + def __init__(self, val, next, random): + self.val = val + self.next = next + self.random = random + + +class Solution(object): + def copyRandomList(self, head): + """ + :type head: Node + :rtype: Node + """ + if head == None: + return None + memories = {} + node = head + while node != None: + cloneNode = Node(node.val, None, None) + memories[node] = cloneNode + node = node.next + node = head + while node: + + memories.get(node).next = memories.get(node.next) + memories.get(node).random = memories.get(node.random) + node = node.next + return memories[head] ``` diff --git "a/data_source/exercises/\344\270\255\347\255\211/python/139.exercises/solution.md" "b/data_source/exercises/\344\270\255\347\255\211/python/139.exercises/solution.md" index cbb6f1e5..29151277 100644 --- "a/data_source/exercises/\344\270\255\347\255\211/python/139.exercises/solution.md" +++ "b/data_source/exercises/\344\270\255\347\255\211/python/139.exercises/solution.md" @@ -35,6 +35,24 @@ ```python +class Solution(object): + def wordBreak(self, s, wordDict): + """ + :type s: str + :type wordDict: List[str] + :rtype: bool + """ + if not s: + return True + lenth = len(s) + dp = [False for i in range(lenth + 1)] + dp[0] = True + for i in range(1, lenth + 1): + for j in range(i): + if dp[j] and s[j:i] in wordDict: + dp[i] = True + break + return dp[-1] ``` diff --git "a/data_source/exercises/\344\270\255\347\255\211/python/142.exercises/solution.md" "b/data_source/exercises/\344\270\255\347\255\211/python/142.exercises/solution.md" index 200c25a2..90582731 100644 --- "a/data_source/exercises/\344\270\255\347\255\211/python/142.exercises/solution.md" +++ "b/data_source/exercises/\344\270\255\347\255\211/python/142.exercises/solution.md" @@ -58,7 +58,23 @@ ## template ```python - +class ListNode: + def __init__(self, x): + self.val = x + self.next = None + +class Solution(object): + def detectCycle(self, head): + s = set() + + node = head + while node is not None: + if node in s: + return node + else: + s.add(node) + node = node.next + return None ``` diff --git "a/data_source/exercises/\344\270\255\347\255\211/python/143.exercises/solution.md" "b/data_source/exercises/\344\270\255\347\255\211/python/143.exercises/solution.md" index bbeb773d..71d5062a 100644 --- "a/data_source/exercises/\344\270\255\347\255\211/python/143.exercises/solution.md" +++ "b/data_source/exercises/\344\270\255\347\255\211/python/143.exercises/solution.md" @@ -40,6 +40,40 @@ ## template ```python +class ListNode: + def __init__(self, x): + self.val = x + self.next = None + +class Solution(object): + def reorderList(self, head): + """ + :type head: ListNode + :rtype: None Do not return anything, modify head in-place instead. + """ + + if not head: + return + + stack = [] + s = head + + while s.next: + stack.append(s.next) + s = s.next + + s = head + + n = 0 + while stack: + if n % 2 == 0: + one = stack.pop() + else: + one = stack.pop(0) + one.next = None + s.next = one + s = s.next + n += 1 ``` diff --git "a/data_source/exercises/\344\270\255\347\255\211/python/146.exercises/solution.md" "b/data_source/exercises/\344\270\255\347\255\211/python/146.exercises/solution.md" index 55476871..c9752dc7 100644 --- "a/data_source/exercises/\344\270\255\347\255\211/python/146.exercises/solution.md" +++ "b/data_source/exercises/\344\270\255\347\255\211/python/146.exercises/solution.md" @@ -58,6 +58,49 @@ lRUCache.get(4); // 返回 4 ```python +class LRUCache: + def __init__(self, capacity): + """ + :type capacity: int + """ + self.maxlength = capacity + self.array = {} + self.array_list = [] + + def get(self, key): + """ + :type key: int + :rtype: int + """ + value = self.array.get(key) + + if value is not None and self.array_list[0] is not key: + index = self.array_list.index(key) + self.array_list.pop(index) + self.array_list.insert(0, key) + + value = value if value is not None else -1 + return value + + def put(self, key, value): + """ + :type key: int + :type value: int + :rtype: void + """ + + if self.array.get(key) is not None: + index = self.array_list.index(key) + self.array.pop(key) + self.array_list.pop(index) + + if len(self.array_list) >= self.maxlength: + key_t = self.array_list.pop(self.maxlength - 1) + self.array.pop(key_t) + + self.array[key] = value + self.array_list.insert(0, key) + ``` diff --git "a/data_source/exercises/\344\270\255\347\255\211/python/147.exercises/solution.md" "b/data_source/exercises/\344\270\255\347\255\211/python/147.exercises/solution.md" index 9a00c061..44d25d53 100644 --- "a/data_source/exercises/\344\270\255\347\255\211/python/147.exercises/solution.md" +++ "b/data_source/exercises/\344\270\255\347\255\211/python/147.exercises/solution.md" @@ -35,6 +35,49 @@ ```python +class LRUCache: + def __init__(self, capacity): + """ + :type capacity: int + """ + self.maxlength = capacity + self.array = {} + self.array_list = [] + + def get(self, key): + """ + :type key: int + :rtype: int + """ + value = self.array.get(key) + + if value is not None and self.array_list[0] is not key: + index = self.array_list.index(key) + self.array_list.pop(index) + self.array_list.insert(0, key) + + value = value if value is not None else -1 + return value + + def put(self, key, value): + """ + :type key: int + :type value: int + :rtype: void + """ + + if self.array.get(key) is not None: + index = self.array_list.index(key) + self.array.pop(key) + self.array_list.pop(index) + + if len(self.array_list) >= self.maxlength: + key_t = self.array_list.pop(self.maxlength - 1) + self.array.pop(key_t) + + self.array[key] = value + self.array_list.insert(0, key) + ``` diff --git "a/data_source/exercises/\344\270\255\347\255\211/python/148.exercises/solution.md" "b/data_source/exercises/\344\270\255\347\255\211/python/148.exercises/solution.md" index c55d8eaf..20b37e58 100644 --- "a/data_source/exercises/\344\270\255\347\255\211/python/148.exercises/solution.md" +++ "b/data_source/exercises/\344\270\255\347\255\211/python/148.exercises/solution.md" @@ -44,7 +44,53 @@ ## template ```python - +class ListNode: + def __init__(self, x): + self.val = x + self.next = None + +class Solution: + def sortList(self, head: ListNode) -> ListNode: + if head == None: + return None + else: + return self.mergeSort(head) + + def mergeSort(self, head): + if head.next == None: + return head + fast = head + slow = head + pre = None + + while fast != None and fast.next != None: + pre = slow + slow = slow.next + fast = fast.next.next + pre.next = None + + left = self.mergeSort(head) + right = self.mergeSort(slow) + + return self.merge(left, right) + + def merge(self, left, right): + tempHead = ListNode(0) + cur = tempHead + while left != None and right != None: + if left.val <= right.val: + cur.next = left + cur = cur.next + left = left.next + else: + cur.next = right + cur = cur.next + right = right.next + if left != None: + cur.next = left + if right != None: + cur.next = right + return tempHead.next ``` diff --git "a/data_source/exercises/\344\270\255\347\255\211/python/150.exercises/solution.md" "b/data_source/exercises/\344\270\255\347\255\211/python/150.exercises/solution.md" index 31c509b7..af5dbf33 100644 --- "a/data_source/exercises/\344\270\255\347\255\211/python/150.exercises/solution.md" +++ "b/data_source/exercises/\344\270\255\347\255\211/python/150.exercises/solution.md" @@ -77,6 +77,35 @@ ## template ```python +class Solution(object): + def evalRPN(self, tokens): + """ + :type tokens: List[str] + :rtype: int + """ + stack = [] + for token in tokens: + + if token not in ["+", "-", "*", "/"]: + stack.append(int(token)) + else: + + num1 = stack.pop() + num2 = stack.pop() + if token == "+": + stack.append(num1 + num2) + elif token == "-": + stack.append(num2 - num1) + elif token == "*": + stack.append(num1 * num2) + elif token == "/": + if num1 * num2 < 0: + result = -((-num2) // num1) + stack.append(result) + else: + stack.append(num2 // num1) + print(stack) + return stack.pop() ``` diff --git "a/data_source/exercises/\344\270\255\347\255\211/python/151.exercises/solution.md" "b/data_source/exercises/\344\270\255\347\255\211/python/151.exercises/solution.md" index 0e953108..c4eab5d2 100644 --- "a/data_source/exercises/\344\270\255\347\255\211/python/151.exercises/solution.md" +++ "b/data_source/exercises/\344\270\255\347\255\211/python/151.exercises/solution.md" @@ -78,6 +78,16 @@ ## template ```python +class Solution: + def reverseWords(self, s: str) -> str: + str_list = s.split() + s1 = "" + for n, i in enumerate(str_list[::-1]): + if n == len(str_list) - 1: + s1 = s1 + i + else: + s1 = s1 + i + " " + return s1 ``` diff --git "a/data_source/exercises/\344\270\255\347\255\211/python/152.exercises/solution.md" "b/data_source/exercises/\344\270\255\347\255\211/python/152.exercises/solution.md" index 3fb50e56..a6e5521d 100644 --- "a/data_source/exercises/\344\270\255\347\255\211/python/152.exercises/solution.md" +++ "b/data_source/exercises/\344\270\255\347\255\211/python/152.exercises/solution.md" @@ -22,6 +22,31 @@ ```python +class Solution: + def maxProduct(self, nums: List[int]) -> int: + if len(nums) == 0: + return 0 + + length = len(nums) + + dp = [[0] * 2 for _ in range(length)] + + dp[0][0] = nums[0] + dp[0][1] = nums[0] + + for i in range(1, length): + + if nums[i] > 0: + dp[i][0] = min(nums[i], dp[i - 1][0] * nums[i]) + dp[i][1] = max(nums[i], dp[i - 1][1] * nums[i]) + else: + dp[i][0] = min(nums[i], dp[i - 1][1] * nums[i]) + dp[i][1] = max(nums[i], dp[i - 1][0] * nums[i]) + + res = dp[0][1] + for i in range(1, length): + res = max(res, dp[i][1]) + return res ``` diff --git "a/data_source/exercises/\344\270\255\347\255\211/python/153.exercises/solution.md" "b/data_source/exercises/\344\270\255\347\255\211/python/153.exercises/solution.md" index a3c217cd..95cd2d43 100644 --- "a/data_source/exercises/\344\270\255\347\255\211/python/153.exercises/solution.md" +++ "b/data_source/exercises/\344\270\255\347\255\211/python/153.exercises/solution.md" @@ -53,6 +53,24 @@ ```python +class Solution(object): + def findMin(self, nums): + + flag = True + if nums[0] < nums[-1]: + flag = True + else: + flag = False + + for i in range(1, len(nums)): + if flag: + if nums[i] < nums[i - 1]: + return nums[i] + else: + if nums[len(nums) - i] < nums[len(nums) - 1 - i]: + return nums[len(nums) - i] + return nums[0] + ``` diff --git "a/data_source/exercises/\344\270\255\347\255\211/python/156.exercises/solution.md" "b/data_source/exercises/\344\270\255\347\255\211/python/156.exercises/solution.md" deleted file mode 100644 index b7d60fca..00000000 --- "a/data_source/exercises/\344\270\255\347\255\211/python/156.exercises/solution.md" +++ /dev/null @@ -1,36 +0,0 @@ -# 上下翻转二叉树 - - - -## template - -```python - - -``` - -## 答案 - -```python - -``` - -## 选项 - -### A - -```python - -``` - -### B - -```python - -``` - -### C - -```python - -``` \ No newline at end of file diff --git "a/data_source/exercises/\344\270\255\347\255\211/python/159.exercises/solution.json" "b/data_source/exercises/\344\270\255\347\255\211/python/159.exercises/solution.json" deleted file mode 100644 index 562e2e07..00000000 --- "a/data_source/exercises/\344\270\255\347\255\211/python/159.exercises/solution.json" +++ /dev/null @@ -1,7 +0,0 @@ -{ - "type": "code_options", - "source": "solution.md", - "exercise_id": "9f961ad0206648198ba16c674bd376f7", - "author": "csdn.net", - "keywords": "哈希表,字符串,滑动窗口" -} \ No newline at end of file diff --git "a/data_source/exercises/\344\270\255\347\255\211/python/159.exercises/solution.md" "b/data_source/exercises/\344\270\255\347\255\211/python/159.exercises/solution.md" deleted file mode 100644 index f4d564fa..00000000 --- "a/data_source/exercises/\344\270\255\347\255\211/python/159.exercises/solution.md" +++ /dev/null @@ -1,36 +0,0 @@ -# 至多包含两个不同字符的最长子串 - - - -## template - -```python - - -``` - -## 答案 - -```python - -``` - -## 选项 - -### A - -```python - -``` - -### B - -```python - -``` - -### C - -```python - -``` \ No newline at end of file diff --git "a/data_source/exercises/\344\270\255\347\255\211/python/161.exercises/solution.md" "b/data_source/exercises/\344\270\255\347\255\211/python/161.exercises/solution.md" deleted file mode 100644 index b71f1c11..00000000 --- "a/data_source/exercises/\344\270\255\347\255\211/python/161.exercises/solution.md" +++ /dev/null @@ -1,36 +0,0 @@ -# 相隔为 1 的编辑距离 - - - -## template - -```python - - -``` - -## 答案 - -```python - -``` - -## 选项 - -### A - -```python - -``` - -### B - -```python - -``` - -### C - -```python - -``` \ No newline at end of file diff --git "a/data_source/exercises/\344\270\255\347\255\211/python/162.exercises/solution.md" "b/data_source/exercises/\344\270\255\347\255\211/python/162.exercises/solution.md" index 15a260a6..6b37618f 100644 --- "a/data_source/exercises/\344\270\255\347\255\211/python/162.exercises/solution.md" +++ "b/data_source/exercises/\344\270\255\347\255\211/python/162.exercises/solution.md" @@ -40,8 +40,20 @@ ## template ```python +class Solution: + def findPeakElement(self, nums: List[int]) -> int: + low = 0 + high = len(nums) - 1 + while low < high: + mid = int(low - (low - high) / 2) + if nums[mid] < nums[mid + 1]: + low = mid + 1 + else: + high = mid + + return low ``` ## 答案 diff --git "a/data_source/exercises/\344\270\255\347\255\211/python/165.exercises/solution.md" "b/data_source/exercises/\344\270\255\347\255\211/python/165.exercises/solution.md" index 760cd97e..620ed87d 100644 --- "a/data_source/exercises/\344\270\255\347\255\211/python/165.exercises/solution.md" +++ "b/data_source/exercises/\344\270\255\347\255\211/python/165.exercises/solution.md" @@ -69,8 +69,48 @@ ## template ```python - - +class Solution(object): + def compareVersion(self, version1, version2): + """ + 用split划分 转换为int 比较即可 + :type version1: str + :type version2: str + :rtype: int + """ + com1 = version1.split(".") + com2 = version2.split(".") + + if len(com1) != len(com2): + + if len(com1) > len(com2): + for i in range(len(com2)): + if int(com1[i]) > int(com2[i]): + return 1 + elif int(com1[i]) < int(com2[i]): + return -1 + for i in range(len(com2), len(com1)): + if int(com1[i]) != 0: + return 1 + return 0 + else: + for i in range(len(com1)): + if int(com1[i]) > int(com2[i]): + return 1 + elif int(com1[i]) < int(com2[i]): + return -1 + for i in range(len(com1), len(com2)): + if int(com2[i]) != 0: + return -1 + return 0 + + for i in range(len(com1)): + if int(com1[i]) > int(com2[i]): + return 1 + elif int(com1[i]) < int(com2[i]): + return -1 + else: + continue + return 0 ``` ## 答案 diff --git "a/data_source/exercises/\344\270\255\347\255\211/python/166.exercises/solution.md" "b/data_source/exercises/\344\270\255\347\255\211/python/166.exercises/solution.md" index 0184dbc8..955b20b7 100644 --- "a/data_source/exercises/\344\270\255\347\255\211/python/166.exercises/solution.md" +++ "b/data_source/exercises/\344\270\255\347\255\211/python/166.exercises/solution.md" @@ -59,6 +59,45 @@ ```python +class Solution(object): + def fractionToDecimal(self, numerator, denominator): + + if numerator < 0 and denominator < 0: + numerator, denominator = -numerator, -denominator + + u = (numerator < 0) ^ (denominator < 0) + + numerator = abs(numerator) + denominator = abs(denominator) + numerator = numerator % denominator + + if numerator == 0: + return str(numerator // denominator) + + s = str(abs(numerator) // denominator) + "." + q = {} + l = [] + while numerator < denominator: + numerator = numerator * 10 + l.append(numerator) + q[numerator] = numerator // denominator + numerator = numerator % denominator * 10 + + while numerator not in q and numerator != 0: + l.append(numerator) + q[numerator] = numerator // denominator + numerator = numerator % denominator + numerator = numerator * 10 + + for i in range(0, len(l)): + if numerator == l[i]: + s = s + "(" + s = s + str(q[l[i]]) + if "(" in s: + s = s + ")" + if u: + s = "-" + s + return s ``` diff --git "a/data_source/exercises/\344\270\255\347\255\211/python/173.exercises/solution.md" "b/data_source/exercises/\344\270\255\347\255\211/python/173.exercises/solution.md" index 6805a02b..7aa84111 100644 --- "a/data_source/exercises/\344\270\255\347\255\211/python/173.exercises/solution.md" +++ "b/data_source/exercises/\344\270\255\347\255\211/python/173.exercises/solution.md" @@ -61,7 +61,43 @@ bSTIterator.hasNext(); // 返回 False ## template ```python - +class TreeNode: + def __init__(self, x): + self.val = x + self.left = None + self.right = None + +class BSTIterator: + def __init__(self, root: TreeNode): + self.index = -1 + self.node_list = [] + self._iterator(root) + + def _iterator(self, root): + if not root: + return + self._iterator(root.left) + self.node_list.append(root.val) + self._iterator(root.right) + + def next(self) -> int: + """ + @return the next smallest number + """ + self.index += 1 + return self.node_list[self.index] + + def hasNext(self) -> bool: + """ + @return whether we have a next smallest number + """ + return self.index + 1 < len(self.node_list) + + +# Your BSTIterator object will be instantiated and called as such: +# obj = BSTIterator(root) +# param_1 = obj.next() +# param_2 = obj.hasNext() ``` diff --git "a/data_source/exercises/\344\270\255\347\255\211/python/177.exercises/solution.json" "b/data_source/exercises/\344\270\255\347\255\211/python/177.exercises/solution.json" deleted file mode 100644 index 90e12cbc..00000000 --- "a/data_source/exercises/\344\270\255\347\255\211/python/177.exercises/solution.json" +++ /dev/null @@ -1,7 +0,0 @@ -{ - "type": "code_options", - "source": "solution.md", - "exercise_id": "75cb32f560dc4a41850c41b8a52f3e09", - "author": "csdn.net", - "keywords": "数据库" -} \ No newline at end of file diff --git "a/data_source/exercises/\344\270\255\347\255\211/python/177.exercises/solution.md" "b/data_source/exercises/\344\270\255\347\255\211/python/177.exercises/solution.md" deleted file mode 100644 index 18ae30c3..00000000 --- "a/data_source/exercises/\344\270\255\347\255\211/python/177.exercises/solution.md" +++ /dev/null @@ -1,55 +0,0 @@ -# 第N高的薪水 - -
编写一个 SQL 查询,获取 Employee
表中第 n 高的薪水(Salary)。
+----+--------+ -| Id | Salary | -+----+--------+ -| 1 | 100 | -| 2 | 200 | -| 3 | 300 | -+----+--------+ -- -
例如上述 Employee
表,n = 2 时,应返回第二高的薪水 200
。如果不存在第 n 高的薪水,那么查询应返回 null
。
+------------------------+ -| getNthHighestSalary(2) | -+------------------------+ -| 200 | -+------------------------+ -- - -## template - -```python - - -``` - -## 答案 - -```python - -``` - -## 选项 - -### A - -```python - -``` - -### B - -```python - -``` - -### C - -```python - -``` \ No newline at end of file diff --git "a/data_source/exercises/\344\270\255\347\255\211/python/178.exercises/config.json" "b/data_source/exercises/\344\270\255\347\255\211/python/178.exercises/config.json" deleted file mode 100644 index 3a90650c..00000000 --- "a/data_source/exercises/\344\270\255\347\255\211/python/178.exercises/config.json" +++ /dev/null @@ -1,10 +0,0 @@ -{ - "node_id": "dailycode-1c04e099a7fe4c5a8807cb714cccb545", - "keywords": [], - "children": [], - "keywords_must": [], - "keywords_forbid": [], - "export": [ - "solution.json" - ] -} \ No newline at end of file diff --git "a/data_source/exercises/\344\270\255\347\255\211/python/178.exercises/solution.json" "b/data_source/exercises/\344\270\255\347\255\211/python/178.exercises/solution.json" deleted file mode 100644 index 35f798b1..00000000 --- "a/data_source/exercises/\344\270\255\347\255\211/python/178.exercises/solution.json" +++ /dev/null @@ -1,7 +0,0 @@ -{ - "type": "code_options", - "source": "solution.md", - "exercise_id": "270e7864b56d4254955b30b93c85451b", - "author": "csdn.net", - "keywords": "数据库" -} \ No newline at end of file diff --git "a/data_source/exercises/\344\270\255\347\255\211/python/178.exercises/solution.md" "b/data_source/exercises/\344\270\255\347\255\211/python/178.exercises/solution.md" deleted file mode 100644 index d297fbb1..00000000 --- "a/data_source/exercises/\344\270\255\347\255\211/python/178.exercises/solution.md" +++ /dev/null @@ -1,67 +0,0 @@ -# 分数排名 - -
编写一个 SQL 查询来实现分数排名。
- -如果两个分数相同,则两个分数排名(Rank)相同。请注意,平分后的下一个名次应该是下一个连续的整数值。换句话说,名次之间不应该有“间隔”。
- -+----+-------+ -| Id | Score | -+----+-------+ -| 1 | 3.50 | -| 2 | 3.65 | -| 3 | 4.00 | -| 4 | 3.85 | -| 5 | 4.00 | -| 6 | 3.65 | -+----+-------+ -- -
例如,根据上述给定的 Scores
表,你的查询应该返回(按分数从高到低排列):
+-------+------+ -| Score | Rank | -+-------+------+ -| 4.00 | 1 | -| 4.00 | 1 | -| 3.85 | 2 | -| 3.65 | 3 | -| 3.65 | 3 | -| 3.50 | 4 | -+-------+------+ -- -
重要提示:对于 MySQL 解决方案,如果要转义用作列名的保留字,可以在关键字之前和之后使用撇号。例如 `Rank`
- - -## template - -```python - - -``` - -## 答案 - -```python - -``` - -## 选项 - -### A - -```python - -``` - -### B - -```python - -``` - -### C - -```python - -``` \ No newline at end of file diff --git "a/data_source/exercises/\344\270\255\347\255\211/python/179.exercises/solution.md" "b/data_source/exercises/\344\270\255\347\255\211/python/179.exercises/solution.md" index a046ca95..fe8bd064 100644 --- "a/data_source/exercises/\344\270\255\347\255\211/python/179.exercises/solution.md" +++ "b/data_source/exercises/\344\270\255\347\255\211/python/179.exercises/solution.md" @@ -47,6 +47,22 @@ ```python +class Solution(object): + def largestNumber(self, nums): + n = len(nums) + + for i in range(n): + for j in range(n - i - 1): + temp_1 = str(nums[j]) + temp_2 = str(nums[j + 1]) + if int(temp_1 + temp_2) < int(temp_2 + temp_1): + temp = nums[j] + nums[j] = nums[j + 1] + nums[j + 1] = temp + output = "" + for num in nums: + output = output + str(num) + return str(int(output)) ``` diff --git "a/data_source/exercises/\344\270\255\347\255\211/python/180.exercises/config.json" "b/data_source/exercises/\344\270\255\347\255\211/python/180.exercises/config.json" deleted file mode 100644 index 6c72a837..00000000 --- "a/data_source/exercises/\344\270\255\347\255\211/python/180.exercises/config.json" +++ /dev/null @@ -1,10 +0,0 @@ -{ - "node_id": "dailycode-ddc469a905d540c0947b071e3a1f2104", - "keywords": [], - "children": [], - "keywords_must": [], - "keywords_forbid": [], - "export": [ - "solution.json" - ] -} \ No newline at end of file diff --git "a/data_source/exercises/\344\270\255\347\255\211/python/180.exercises/solution.json" "b/data_source/exercises/\344\270\255\347\255\211/python/180.exercises/solution.json" deleted file mode 100644 index 42810c39..00000000 --- "a/data_source/exercises/\344\270\255\347\255\211/python/180.exercises/solution.json" +++ /dev/null @@ -1,7 +0,0 @@ -{ - "type": "code_options", - "source": "solution.md", - "exercise_id": "d914beb248f541e7b429b27bc0e74fc7", - "author": "csdn.net", - "keywords": "数据库" -} \ No newline at end of file diff --git "a/data_source/exercises/\344\270\255\347\255\211/python/180.exercises/solution.md" "b/data_source/exercises/\344\270\255\347\255\211/python/180.exercises/solution.md" deleted file mode 100644 index 86f81f27..00000000 --- "a/data_source/exercises/\344\270\255\347\255\211/python/180.exercises/solution.md" +++ /dev/null @@ -1,81 +0,0 @@ -# 连续出现的数字 - -表:Logs
-+-------------+---------+ -| Column Name | Type | -+-------------+---------+ -| id | int | -| num | varchar | -+-------------+---------+ -id 是这个表的主键。- -
- -
编写一个 SQL 查询,查找所有至少连续出现三次的数字。
- -返回的结果表中的数据可以按 任意顺序 排列。
- -- -
查询结果格式如下面的例子所示:
- -- -
-Logs 表: -+----+-----+ -| Id | Num | -+----+-----+ -| 1 | 1 | -| 2 | 1 | -| 3 | 1 | -| 4 | 2 | -| 5 | 1 | -| 6 | 2 | -| 7 | 2 | -+----+-----+ - -Result 表: -+-----------------+ -| ConsecutiveNums | -+-----------------+ -| 1 | -+-----------------+ -1 是唯一连续出现至少三次的数字。 -- - -## template - -```python - - -``` - -## 答案 - -```python - -``` - -## 选项 - -### A - -```python - -``` - -### B - -```python - -``` - -### C - -```python - -``` \ No newline at end of file diff --git "a/data_source/exercises/\344\270\255\347\255\211/python/184.exercises/config.json" "b/data_source/exercises/\344\270\255\347\255\211/python/184.exercises/config.json" deleted file mode 100644 index 7fa62391..00000000 --- "a/data_source/exercises/\344\270\255\347\255\211/python/184.exercises/config.json" +++ /dev/null @@ -1,10 +0,0 @@ -{ - "node_id": "dailycode-ef833ac6c03843cfb0b6942582202b85", - "keywords": [], - "children": [], - "keywords_must": [], - "keywords_forbid": [], - "export": [ - "solution.json" - ] -} \ No newline at end of file diff --git "a/data_source/exercises/\344\270\255\347\255\211/python/184.exercises/solution.json" "b/data_source/exercises/\344\270\255\347\255\211/python/184.exercises/solution.json" deleted file mode 100644 index 58f7ac34..00000000 --- "a/data_source/exercises/\344\270\255\347\255\211/python/184.exercises/solution.json" +++ /dev/null @@ -1,7 +0,0 @@ -{ - "type": "code_options", - "source": "solution.md", - "exercise_id": "23a7c3aaad084cc9898bb5b78c0a8f1a", - "author": "csdn.net", - "keywords": "数据库" -} \ No newline at end of file diff --git "a/data_source/exercises/\344\270\255\347\255\211/python/184.exercises/solution.md" "b/data_source/exercises/\344\270\255\347\255\211/python/184.exercises/solution.md" deleted file mode 100644 index 334ebefa..00000000 --- "a/data_source/exercises/\344\270\255\347\255\211/python/184.exercises/solution.md" +++ /dev/null @@ -1,70 +0,0 @@ -# 部门工资最高的员工 - -
Employee
表包含所有员工信息,每个员工有其对应的 Id, salary 和 department Id。
+----+-------+--------+--------------+ -| Id | Name | Salary | DepartmentId | -+----+-------+--------+--------------+ -| 1 | Joe | 70000 | 1 | -| 2 | Jim | 90000 | 1 | -| 3 | Henry | 80000 | 2 | -| 4 | Sam | 60000 | 2 | -| 5 | Max | 90000 | 1 | -+----+-------+--------+--------------+- -
Department
表包含公司所有部门的信息。
+----+----------+ -| Id | Name | -+----+----------+ -| 1 | IT | -| 2 | Sales | -+----+----------+- -
编写一个 SQL 查询,找出每个部门工资最高的员工。对于上述表,您的 SQL 查询应返回以下行(行的顺序无关紧要)。
- -+------------+----------+--------+ -| Department | Employee | Salary | -+------------+----------+--------+ -| IT | Max | 90000 | -| IT | Jim | 90000 | -| Sales | Henry | 80000 | -+------------+----------+--------+- -
解释:
- -Max 和 Jim 在 IT 部门的工资都是最高的,Henry 在销售部的工资最高。
- - -## template - -```python - - -``` - -## 答案 - -```python - -``` - -## 选项 - -### A - -```python - -``` - -### B - -```python - -``` - -### C - -```python - -``` \ No newline at end of file diff --git "a/data_source/exercises/\344\270\255\347\255\211/python/186.exercises/config.json" "b/data_source/exercises/\344\270\255\347\255\211/python/186.exercises/config.json" deleted file mode 100644 index 5946329d..00000000 --- "a/data_source/exercises/\344\270\255\347\255\211/python/186.exercises/config.json" +++ /dev/null @@ -1,10 +0,0 @@ -{ - "node_id": "dailycode-0237ef7add04423ba14101b215134c1d", - "keywords": [], - "children": [], - "keywords_must": [], - "keywords_forbid": [], - "export": [ - "solution.json" - ] -} \ No newline at end of file diff --git "a/data_source/exercises/\344\270\255\347\255\211/python/186.exercises/solution.md" "b/data_source/exercises/\344\270\255\347\255\211/python/186.exercises/solution.md" deleted file mode 100644 index 65ea7140..00000000 --- "a/data_source/exercises/\344\270\255\347\255\211/python/186.exercises/solution.md" +++ /dev/null @@ -1,36 +0,0 @@ -# 翻转字符串里的单词 II - - - -## template - -```python - - -``` - -## 答案 - -```python - -``` - -## 选项 - -### A - -```python - -``` - -### B - -```python - -``` - -### C - -```python - -``` \ No newline at end of file diff --git "a/data_source/exercises/\344\270\255\347\255\211/python/187.exercises/solution.md" "b/data_source/exercises/\344\270\255\347\255\211/python/187.exercises/solution.md" index 557e1908..e8e6bb6c 100644 --- "a/data_source/exercises/\344\270\255\347\255\211/python/187.exercises/solution.md" +++ "b/data_source/exercises/\344\270\255\347\255\211/python/187.exercises/solution.md" @@ -33,6 +33,19 @@ ## template ```python +class Solution: + def findRepeatedDnaSequences(self, s: str) -> List[str]: + n = len(s) + res = [] + dic = {} + for i in range(n - 9): + if s[i : i + 10] not in dic: + dic[s[i : i + 10]] = 1 + else: + dic[s[i : i + 10]] += 1 + if dic[s[i : i + 10]] == 2: + res.append(s[i : i + 10]) + return res ``` diff --git "a/data_source/exercises/\344\270\255\347\255\211/python/189.exercises/solution.md" "b/data_source/exercises/\344\270\255\347\255\211/python/189.exercises/solution.md" index 327f5686..b24fb07e 100644 --- "a/data_source/exercises/\344\270\255\347\255\211/python/189.exercises/solution.md" +++ "b/data_source/exercises/\344\270\255\347\255\211/python/189.exercises/solution.md" @@ -50,6 +50,18 @@ ## template ```python +class Solution: + def rotate(self, nums: List[int], k: int) -> None: + """ + Do not return anything, modify nums in-place instead. + """ + n = 0 + while n < k: + c = nums.pop() + nums.insert(0, c) + + n += 1 + return nums ``` diff --git "a/data_source/exercises/\344\270\255\347\255\211/python/192.exercises/config.json" "b/data_source/exercises/\344\270\255\347\255\211/python/192.exercises/config.json" deleted file mode 100644 index 8eec8096..00000000 --- "a/data_source/exercises/\344\270\255\347\255\211/python/192.exercises/config.json" +++ /dev/null @@ -1,10 +0,0 @@ -{ - "node_id": "dailycode-e6479018b631496fa241dbade3d24226", - "keywords": [], - "children": [], - "keywords_must": [], - "keywords_forbid": [], - "export": [ - "solution.json" - ] -} \ No newline at end of file diff --git "a/data_source/exercises/\344\270\255\347\255\211/python/192.exercises/solution.md" "b/data_source/exercises/\344\270\255\347\255\211/python/192.exercises/solution.md" deleted file mode 100644 index 0cdfdc8f..00000000 --- "a/data_source/exercises/\344\270\255\347\255\211/python/192.exercises/solution.md" +++ /dev/null @@ -1,68 +0,0 @@ -# 统计词频 - -写一个 bash 脚本以统计一个文本文件 words.txt
中每个单词出现的频率。
为了简单起见,你可以假设:
- -words.txt
只包括小写字母和 ' '
。示例:
- -假设 words.txt
内容如下:
the day is sunny the the -the sunny is is -- -
你的脚本应当输出(以词频降序排列):
- -the 4 -is 3 -sunny 2 -day 1 -- -
说明:
- -给定一个文件 file.txt
,转置它的内容。
你可以假设每行列数相同,并且每个字段由 ' '
分隔。
- -
示例:
- -假设 file.txt
文件内容如下:
-name age -alice 21 -ryan 30 -- -
应当输出:
- --name alice ryan -age 21 30 -- - -## template - -```python - - -``` - -## 答案 - -```python - -``` - -## 选项 - -### A - -```python - -``` - -### B - -```python - -``` - -### C - -```python - -``` \ No newline at end of file diff --git "a/data_source/exercises/\344\270\255\347\255\211/python/198.exercises/solution.md" "b/data_source/exercises/\344\270\255\347\255\211/python/198.exercises/solution.md" index 2e6f8dfb..506b70e3 100644 --- "a/data_source/exercises/\344\270\255\347\255\211/python/198.exercises/solution.md" +++ "b/data_source/exercises/\344\270\255\347\255\211/python/198.exercises/solution.md" @@ -37,6 +37,16 @@ ```python +class Solution: + def rob(self, nums: List[int]) -> int: + if not nums: + return 0 + if len(nums) == 1: + return nums[0] + dp = [nums[0], max(nums[0], nums[1])] + for i in range(2, len(nums)): + dp.append(max(nums[i] + dp[i - 2], dp[i - 1])) + return dp[-1] ``` diff --git "a/data_source/exercises/\344\270\255\347\255\211/python/199.exercises/solution.md" "b/data_source/exercises/\344\270\255\347\255\211/python/199.exercises/solution.md" index c1d766a9..2e344d40 100644 --- "a/data_source/exercises/\344\270\255\347\255\211/python/199.exercises/solution.md" +++ "b/data_source/exercises/\344\270\255\347\255\211/python/199.exercises/solution.md" @@ -40,7 +40,32 @@ ## template ```python - +class TreeNode: + def __init__(self, x): + self.val = x + self.left = None + self.right = None + +class Solution: + def rightSideView(self, root: TreeNode) -> List[int]: + if not root: + return [] + res = [] + curnode = [root] + nexnode = [] + res.append(curnode[0].val) + + while curnode: + for s in curnode: + if s.right: + nexnode.append(s.right) + if s.left: + nexnode.append(s.left) + if nexnode: + res.append(nexnode[0].val) + curnode = nexnode + nexnode = [] + return res ``` diff --git "a/data_source/exercises/\344\270\255\347\255\211/python/200.exercises/solution.md" "b/data_source/exercises/\344\270\255\347\255\211/python/200.exercises/solution.md" index 731bf265..aba42f31 100644 --- "a/data_source/exercises/\344\270\255\347\255\211/python/200.exercises/solution.md" +++ "b/data_source/exercises/\344\270\255\347\255\211/python/200.exercises/solution.md" @@ -48,6 +48,29 @@ ```python +class Solution: + def depthSearch(self, grid, i, j): + if i < 0 or j < 0 or i >= len(grid) or j >= len(grid[0]): + return + if grid[i][j] == "0": + return + grid[i][j] = "0" + self.depthSearch(grid, i - 1, j) + self.depthSearch(grid, i + 1, j) + self.depthSearch(grid, i, j - 1) + self.depthSearch(grid, i, j + 1) + + def numIslands(self, grid: List[List[str]]) -> int: + if not grid: + return 0 + w, h = len(grid[0]), len(grid) + cnt = 0 + for i in range(h): + for j in range(w): + if grid[i][j] == "1": + self.depthSearch(grid, i, j) + cnt += 1 + return cnt ``` diff --git "a/data_source/exercises/\345\233\260\351\232\276/python/115.exercises/solution.md" "b/data_source/exercises/\345\233\260\351\232\276/python/115.exercises/solution.md" index 736b4f49..4e47cd10 100644 --- "a/data_source/exercises/\345\233\260\351\232\276/python/115.exercises/solution.md" +++ "b/data_source/exercises/\345\233\260\351\232\276/python/115.exercises/solution.md" @@ -47,7 +47,21 @@ ```python - +class Solution: + def numDistinct(self, s: str, t: str) -> int: + if t == "" and s == "": + return 0 + if t == "": + return 1 + dp = [[0 for i in range(len(s) + 1)] for j in range(len(t) + 1)] + for j in range(0, len(s) + 1): + dp[0][j] = 1 + for i in range(1, len(t) + 1): + for j in range(1, len(s) + 1): + dp[i][j] = dp[i][j - 1] + if s[j - 1] == t[i - 1]: + dp[i][j] += dp[i - 1][j - 1] + return dp[-1][-1] ``` ## 答案 diff --git "a/data_source/exercises/\345\233\260\351\232\276/python/123.exercises/solution.md" "b/data_source/exercises/\345\233\260\351\232\276/python/123.exercises/solution.md" index 6b8fdafd..7c3ef454 100644 --- "a/data_source/exercises/\345\233\260\351\232\276/python/123.exercises/solution.md" +++ "b/data_source/exercises/\345\233\260\351\232\276/python/123.exercises/solution.md" @@ -53,7 +53,22 @@ ## template ```python - +class Solution: + def maxProfit(self, prices: List[int]) -> int: + if len(prices) == 0: + return 0 + k = 2 + n = len(prices) + dp_i_1_0 = 0 + dp_i_1_1 = -prices[0] + dp_i_2_0 = 0 + dp_i_2_1 = -prices[0] + for i in range(1, n): + dp_i_1_0 = max(dp_i_1_0, dp_i_1_1 + prices[i]) + dp_i_1_1 = max(dp_i_1_1, -prices[i]) + dp_i_2_0 = max(dp_i_2_0, dp_i_2_1 + prices[i]) + dp_i_2_1 = max(dp_i_2_1, dp_i_1_0 - prices[i]) + return dp_i_2_0 ``` diff --git "a/data_source/exercises/\345\233\260\351\232\276/python/124.exercises/solution.md" "b/data_source/exercises/\345\233\260\351\232\276/python/124.exercises/solution.md" index d0c3ab07..bb3342d1 100644 --- "a/data_source/exercises/\345\233\260\351\232\276/python/124.exercises/solution.md" +++ "b/data_source/exercises/\345\233\260\351\232\276/python/124.exercises/solution.md" @@ -37,6 +37,25 @@ ```python +class Solution: + def __init__(self): + self.result = float("-inf") + + def maxPathSum(self, root: TreeNode) -> int: + if root == None: + return 0 + self.getMax(root) + return self.result + + def getMax(self, root): + if root == None: + return 0 + + left = max(0, self.getMax(root.left)) + right = max(0, self.getMax(root.right)) + + self.result = max(self.result, left + right + root.val) + return max(left, right) + root.val ``` diff --git "a/data_source/exercises/\345\233\260\351\232\276/python/126.exercises/solution.md" "b/data_source/exercises/\345\233\260\351\232\276/python/126.exercises/solution.md" index cb60e655..a0fb31b7 100644 --- "a/data_source/exercises/\345\233\260\351\232\276/python/126.exercises/solution.md" +++ "b/data_source/exercises/\345\233\260\351\232\276/python/126.exercises/solution.md" @@ -52,7 +52,36 @@ ## template ```python - +class Solution: + def findLadders(self, beginWord: str, endWord: str, wordList: List[str]) -> List[List[str]]: + import collections + ans = [] + steps = float("inf") + if not beginWord or not endWord or not wordList or endWord not in wordList: + return [] + word_dict = collections.defaultdict(list) + L = len(beginWord) + for word in wordList: + for i in range(L): + word_dict[word[:i] + "*" + word[i+1:]].append(word) + queue = [[beginWord]] + cost = {beginWord : 0} + while queue: + words_list= queue.pop(0) + cur_word = words_list[-1] + if cur_word == endWord: + ans.append(words_list[:]) + else: + for i in range(L): + intermediate_word = cur_word[:i] + "*" + cur_word[i+1:] + for word in word_dict[intermediate_word]: + w_l_temp = words_list[:] + if word not in cost or cost[word] >= cost[cur_word] + 1: + cost[word] = cost[cur_word] + 1 + w_l_temp.append(word) + queue.append(w_l_temp[:]) + + return ans ``` diff --git "a/data_source/exercises/\345\233\260\351\232\276/python/127.exercises/solution.md" "b/data_source/exercises/\345\233\260\351\232\276/python/127.exercises/solution.md" index 45c20576..d8310499 100644 --- "a/data_source/exercises/\345\233\260\351\232\276/python/127.exercises/solution.md" +++ "b/data_source/exercises/\345\233\260\351\232\276/python/127.exercises/solution.md" @@ -45,7 +45,46 @@ ## template ```python - +class Solution: + def ladderLength(self, beginWord, endWord, wordList): + """ + :type beginWord: str + :type endWord: str + :type wordList: List[str] + :rtype: int + """ + + if endWord not in wordList: + return 0 + + if beginWord in wordList: + wordList.remove(beginWord) + wordDict = dict() + + for word in wordList: + for i in range(len(word)): + tmp = word[:i] + "_" + word[i + 1 :] + wordDict[tmp] = wordDict.get(tmp, []) + [word] + + stack, visited = [(beginWord, 1)], set() + + while stack: + word, step = stack.pop(0) + if word not in visited: + visited.add(word) + + if word == endWord: + return step + + for i in range(len(word)): + tmp = word[:i] + "_" + word[i + 1 :] + neigh_words = wordDict.get(tmp, []) + + for neigh in neigh_words: + if neigh not in visited: + stack.append((neigh, step + 1)) + + return 0 ``` diff --git "a/data_source/exercises/\345\233\260\351\232\276/python/132.exercises/solution.md" "b/data_source/exercises/\345\233\260\351\232\276/python/132.exercises/solution.md" index 4cd3b222..661fae5c 100644 --- "a/data_source/exercises/\345\233\260\351\232\276/python/132.exercises/solution.md" +++ "b/data_source/exercises/\345\233\260\351\232\276/python/132.exercises/solution.md" @@ -46,7 +46,24 @@ ```python - +class Solution: + def minCut(self, s): + size = len(s) + + is_palindrome = [[False] * size for _ in range(size)] + for r in range(size): + for l in range(r, -1, -1): + if s[l] == s[r] and (r - l <= 2 or is_palindrome[l + 1][r - 1]): + is_palindrome[l][r] = True + + dp = [i for i in range(size)] + for i in range(1, size): + if is_palindrome[0][i]: + dp[i] = 0 + else: + dp[i] = min(dp[j] + 1 for j in range(i) if is_palindrome[j + 1][i]) + + return dp[-1] ``` ## 答案 diff --git "a/data_source/exercises/\345\233\260\351\232\276/python/135.exercises/solution.md" "b/data_source/exercises/\345\233\260\351\232\276/python/135.exercises/solution.md" index 56f234e5..dd11add2 100644 --- "a/data_source/exercises/\345\233\260\351\232\276/python/135.exercises/solution.md" +++ "b/data_source/exercises/\345\233\260\351\232\276/python/135.exercises/solution.md" @@ -33,7 +33,26 @@ ## template ```python - +class Solution(object): + def candy(self, ratings): + """ + :type ratings: List[int] + :rtype: int + """ + if ratings == None: + return 0 + lenth = len(ratings) + dp = [1 for i in range(lenth)] + sum = 0 + for i in range(1, len(ratings)): + if ratings[i] > ratings[i - 1]: + dp[i] = dp[i - 1] + 1 + for i in range(len(ratings) - 2, -1, -1): + if ratings[i] > ratings[i + 1] and dp[i] <= dp[i + 1]: + dp[i] = dp[i + 1] + 1 + for i in range(lenth): + sum += dp[i] + return sum ``` diff --git "a/data_source/exercises/\345\233\260\351\232\276/python/140.exercises/solution.md" "b/data_source/exercises/\345\233\260\351\232\276/python/140.exercises/solution.md" index d2377ae4..45780ba6 100644 --- "a/data_source/exercises/\345\233\260\351\232\276/python/140.exercises/solution.md" +++ "b/data_source/exercises/\345\233\260\351\232\276/python/140.exercises/solution.md" @@ -48,6 +48,36 @@ wordDict = ["cats", "dog", "sand", "and" ## template ```python +class Solution(object): + def dfs(self, low, length, s, res, vaild, path=[]): + if low == length: + res.append(" ".join(path)) + return + for i in range(low, length): + if vaild[low][i]: + self.dfs(i + 1, length, s, res, vaild, path + [s[low : i + 1]]) + + def wordBreak(self, s, wordDict): + """ + :type s: str + :type wordDict: List[str] + :rtype: List[str] + """ + length = len(s) + vaild = [[False] * length for _ in range(length)] + dp = [False for _ in range(length + 1)] + dp[0] = True + wordDict = set(wordDict) + for i in range(1, length + 1): + for j in range(i + 1): + word = s[j:i] + if dp[j] and word in wordDict: + dp[i] = True + vaild[j][i - 1] = True + res = [] + if dp[-1]: + self.dfs(0, length, s, res, vaild) + return res ``` diff --git "a/data_source/exercises/\345\233\260\351\232\276/python/149.exercises/solution.md" "b/data_source/exercises/\345\233\260\351\232\276/python/149.exercises/solution.md" index 924a3994..b9692a5a 100644 --- "a/data_source/exercises/\345\233\260\351\232\276/python/149.exercises/solution.md" +++ "b/data_source/exercises/\345\233\260\351\232\276/python/149.exercises/solution.md" @@ -33,7 +33,34 @@ ## template ```python - +class Solution: + def maxPoints(self, points: List[List[int]]) -> int: + if len(points) <= 2: + return len(points) + maxNum = 0 + for i in range(len(points)): + maxNum = max(maxNum, self.find(points[i], points[:i] + points[i + 1 :])) + return maxNum + 1 + + def find(self, point, pointList): + memories = {} + count = 0 + inf = float("inf") + for curPoint in pointList: + if curPoint[1] == point[1] and curPoint[0] != point[0]: + memories[inf] = memories.get(inf, 0) + 1 + elif curPoint[1] == point[1] and curPoint[0] == point[0]: + + count += 1 + else: + slope = (curPoint[0] - point[0]) / (curPoint[1] - point[1]) + memories[slope] = memories.get(slope, 0) + 1 + if memories: + return count + max(memories.values()) + + else: + + return count ``` diff --git "a/data_source/exercises/\345\233\260\351\232\276/python/154.exercises/solution.md" "b/data_source/exercises/\345\233\260\351\232\276/python/154.exercises/solution.md" index 6620155c..a6996357 100644 --- "a/data_source/exercises/\345\233\260\351\232\276/python/154.exercises/solution.md" +++ "b/data_source/exercises/\345\233\260\351\232\276/python/154.exercises/solution.md" @@ -51,7 +51,19 @@ ```python - +class Solution: + def findMin(self, nums: List[int]) -> int: + left = 0 + right = len(nums) - 1 + while left < right: + mid = left + (right - left) // 2 + if nums[mid] > nums[right]: + left = mid + 1 + elif nums[mid] == nums[right]: + right -= 1 + else: + right = mid + return nums[left] ``` ## 答案 diff --git "a/data_source/exercises/\345\233\260\351\232\276/python/158.exercises/config.json" "b/data_source/exercises/\345\233\260\351\232\276/python/158.exercises/config.json" deleted file mode 100644 index ab049c67..00000000 --- "a/data_source/exercises/\345\233\260\351\232\276/python/158.exercises/config.json" +++ /dev/null @@ -1,10 +0,0 @@ -{ - "node_id": "dailycode-84631fc0702a4a999bce155aaab1d17e", - "keywords": [], - "children": [], - "keywords_must": [], - "keywords_forbid": [], - "export": [ - "solution.json" - ] -} \ No newline at end of file diff --git "a/data_source/exercises/\345\233\260\351\232\276/python/158.exercises/solution.json" "b/data_source/exercises/\345\233\260\351\232\276/python/158.exercises/solution.json" deleted file mode 100644 index d6a0cebe..00000000 --- "a/data_source/exercises/\345\233\260\351\232\276/python/158.exercises/solution.json" +++ /dev/null @@ -1,7 +0,0 @@ -{ - "type": "code_options", - "source": "solution.md", - "exercise_id": "d93105a1777c4ea29f6ee12016e57bdc", - "author": "csdn.net", - "keywords": "字符串,交互,模拟" -} \ No newline at end of file diff --git "a/data_source/exercises/\345\233\260\351\232\276/python/158.exercises/solution.md" "b/data_source/exercises/\345\233\260\351\232\276/python/158.exercises/solution.md" deleted file mode 100644 index d799dd6e..00000000 --- "a/data_source/exercises/\345\233\260\351\232\276/python/158.exercises/solution.md" +++ /dev/null @@ -1,36 +0,0 @@ -# 用 Read4 读取 N 个字符 II - - - -## template - -```python - - -``` - -## 答案 - -```python - -``` - -## 选项 - -### A - -```python - -``` - -### B - -```python - -``` - -### C - -```python - -``` \ No newline at end of file diff --git "a/data_source/exercises/\345\233\260\351\232\276/python/164.exercises/solution.md" "b/data_source/exercises/\345\233\260\351\232\276/python/164.exercises/solution.md" index 3215d310..7f97f2cc 100644 --- "a/data_source/exercises/\345\233\260\351\232\276/python/164.exercises/solution.md" +++ "b/data_source/exercises/\345\233\260\351\232\276/python/164.exercises/solution.md" @@ -27,7 +27,36 @@ ## template ```python - +class Solution(object): + def maximumGap(self, nums): + if len(nums) < 2: + return 0 + min_val, max_val = min(nums), max(nums) + if min_val == max_val: + return 0 + + n = len(nums) + 1 + step = (max_val - min_val) // n + + exist = [0 for _ in range(n + 1)] + max_num = [0 for _ in range(n + 1)] + min_num = [0 for _ in range(n + 1)] + + for num in nums: + idx = self.findBucketIndex(num, min_val, max_val, n) + max_num[idx] = num if not exist[idx] else max(num, max_num[idx]) + min_num[idx] = num if not exist[idx] else min(num, min_num[idx]) + exist[idx] = 1 + res = 0 + pre = max_num[0] + for i in range(1, n + 1): + if exist[i]: + res = max(res, min_num[i] - pre) + pre = max_num[i] + return res + + def findBucketIndex(self, num, min_val, max_val, n): + return int((num - min_val) * n / (max_val - min_val)) ``` diff --git "a/data_source/exercises/\345\233\260\351\232\276/python/174.exercises/solution.md" "b/data_source/exercises/\345\233\260\351\232\276/python/174.exercises/solution.md" index fc635dec..98bc1941 100644 --- "a/data_source/exercises/\345\233\260\351\232\276/python/174.exercises/solution.md" +++ "b/data_source/exercises/\345\233\260\351\232\276/python/174.exercises/solution.md" @@ -61,7 +61,21 @@ table.dungeon, .dungeon th, .dungeon td { ## template ```python +class Solution: + def calculateMinimumHP(self, dungeon: List[List[int]]) -> int: + m = len(dungeon) + n = len(dungeon[0]) + dp = [[float("inf")] * (n + 1) for _ in range(m + 1)] + + dp[m - 1][n] = 1 + dp[m][n - 1] = 1 + + for i in range(m - 1, -1, -1): + for j in range(n - 1, -1, -1): + dp[i][j] = max(min(dp[i][j + 1], dp[i + 1][j]) - dungeon[i][j], 1) + + return dp[0][0] ``` diff --git "a/data_source/exercises/\345\233\260\351\232\276/python/185.exercises/config.json" "b/data_source/exercises/\345\233\260\351\232\276/python/185.exercises/config.json" deleted file mode 100644 index 093b870a..00000000 --- "a/data_source/exercises/\345\233\260\351\232\276/python/185.exercises/config.json" +++ /dev/null @@ -1,10 +0,0 @@ -{ - "node_id": "dailycode-276f914f5c864bc9bcd3f3663cce1600", - "keywords": [], - "children": [], - "keywords_must": [], - "keywords_forbid": [], - "export": [ - "solution.json" - ] -} \ No newline at end of file diff --git "a/data_source/exercises/\345\233\260\351\232\276/python/185.exercises/solution.json" "b/data_source/exercises/\345\233\260\351\232\276/python/185.exercises/solution.json" deleted file mode 100644 index baeab96a..00000000 --- "a/data_source/exercises/\345\233\260\351\232\276/python/185.exercises/solution.json" +++ /dev/null @@ -1,7 +0,0 @@ -{ - "type": "code_options", - "source": "solution.md", - "exercise_id": "899bf9e5b2c247db98f3adae4adf87dc", - "author": "csdn.net", - "keywords": "数据库" -} \ No newline at end of file diff --git "a/data_source/exercises/\345\233\260\351\232\276/python/185.exercises/solution.md" "b/data_source/exercises/\345\233\260\351\232\276/python/185.exercises/solution.md" deleted file mode 100644 index e85639c6..00000000 --- "a/data_source/exercises/\345\233\260\351\232\276/python/185.exercises/solution.md" +++ /dev/null @@ -1,75 +0,0 @@ -# 部门工资前三高的所有员工 - -
Employee
表包含所有员工信息,每个员工有其对应的工号 Id
,姓名 Name
,工资 Salary
和部门编号 DepartmentId
。
+----+-------+--------+--------------+ -| Id | Name | Salary | DepartmentId | -+----+-------+--------+--------------+ -| 1 | Joe | 85000 | 1 | -| 2 | Henry | 80000 | 2 | -| 3 | Sam | 60000 | 2 | -| 4 | Max | 90000 | 1 | -| 5 | Janet | 69000 | 1 | -| 6 | Randy | 85000 | 1 | -| 7 | Will | 70000 | 1 | -+----+-------+--------+--------------+- -
Department
表包含公司所有部门的信息。
+----+----------+ -| Id | Name | -+----+----------+ -| 1 | IT | -| 2 | Sales | -+----+----------+- -
编写一个 SQL 查询,找出每个部门获得前三高工资的所有员工。例如,根据上述给定的表,查询结果应返回:
- -+------------+----------+--------+ -| Department | Employee | Salary | -+------------+----------+--------+ -| IT | Max | 90000 | -| IT | Randy | 85000 | -| IT | Joe | 85000 | -| IT | Will | 70000 | -| Sales | Henry | 80000 | -| Sales | Sam | 60000 | -+------------+----------+--------+- -
解释:
- -IT 部门中,Max 获得了最高的工资,Randy 和 Joe 都拿到了第二高的工资,Will 的工资排第三。销售部门(Sales)只有两名员工,Henry 的工资最高,Sam 的工资排第二。
- - -## template - -```python - - -``` - -## 答案 - -```python - -``` - -## 选项 - -### A - -```python - -``` - -### B - -```python - -``` - -### C - -```python - -``` \ No newline at end of file diff --git "a/data_source/exercises/\345\233\260\351\232\276/python/188.exercises/solution.md" "b/data_source/exercises/\345\233\260\351\232\276/python/188.exercises/solution.md" index 4fa430bd..8da01a9a 100644 --- "a/data_source/exercises/\345\233\260\351\232\276/python/188.exercises/solution.md" +++ "b/data_source/exercises/\345\233\260\351\232\276/python/188.exercises/solution.md" @@ -37,7 +37,28 @@ ## template ```python - +class Solution: + def maxProfit(self, k, prices): + if not prices: + return 0 + n = len(prices) + max_k = n // 2 + if k >= max_k: + res = 0 + for i in range(n - 1): + res += max(0, prices[i + 1] - prices[i]) + return res + else: + max_k = k + + dp = [[[0] * 2 for _ in range(k + 1)] for _ in range(n)] + for i in range(max_k + 1): + dp[0][i][1] = -prices[0] + for i in range(1, n): + for k in range(1, max_k + 1): + dp[i][k][0] = max(dp[i - 1][k][0], dp[i - 1][k][1] + prices[i]) + dp[i][k][1] = max(dp[i - 1][k][1], dp[i - 1][k - 1][0] - prices[i]) + return dp[n - 1][max_k][0] ``` diff --git "a/data_source/exercises/\345\233\260\351\232\276/python/212.exercises/solution.md" "b/data_source/exercises/\345\233\260\351\232\276/python/212.exercises/solution.md" index 4601f6b0..0cf0d174 100644 --- "a/data_source/exercises/\345\233\260\351\232\276/python/212.exercises/solution.md" +++ "b/data_source/exercises/\345\233\260\351\232\276/python/212.exercises/solution.md" @@ -39,7 +39,44 @@ ## template ```python - +class Solution: + def findWords(self, board: List[List[str]], words: List[str]) -> List[str]: + if not board or not board[0] or not words: + return [] + self.root = {} + for word in words: + node = self.root + for char in word: + if char not in node: + node[char] = {} + node = node[char] + node["#"] = word + res = [] + for i in range(len(board)): + for j in range(len(board[0])): + tmp_state = [] + self.dfs(i, j, board, tmp_state, self.root, res) + return res + + def dfs(self, i, j, board, tmp_state, node, res): + if "#" in node and node["#"] not in res: + res.append(node["#"]) + if [i, j] not in tmp_state and board[i][j] in node: + tmp = tmp_state + [[i, j]] + candidate = [] + if i - 1 >= 0: + candidate.append([i - 1, j]) + if i + 1 < len(board): + candidate.append([i + 1, j]) + if j - 1 >= 0: + candidate.append([i, j - 1]) + if j + 1 < len(board[0]): + candidate.append([i, j + 1]) + node = node[board[i][j]] + if "#" in node and node["#"] not in res: + res.append(node["#"]) + for item in candidate: + self.dfs(item[0], item[1], board, tmp, node, res) ``` diff --git "a/data_source/exercises/\345\233\260\351\232\276/python/214.exercises/solution.md" "b/data_source/exercises/\345\233\260\351\232\276/python/214.exercises/solution.md" index fef69756..75be6dbb 100644 --- "a/data_source/exercises/\345\233\260\351\232\276/python/214.exercises/solution.md" +++ "b/data_source/exercises/\345\233\260\351\232\276/python/214.exercises/solution.md" @@ -31,7 +31,16 @@ ## template ```python - +class Solution: + def shortestPalindrome(self, s: str) -> str: + N = len(s) + idx1 = 0 + for idx2 in range(N - 1, -1, -1): + if s[idx1] == s[idx2]: + idx1 += 1 + if idx1 == N: + return s + return s[idx1:][::-1] + self.shortestPalindrome(s[:idx1]) + s[idx1:] ``` diff --git "a/data_source/exercises/\345\233\260\351\232\276/python/218.exercises/solution.md" "b/data_source/exercises/\345\233\260\351\232\276/python/218.exercises/solution.md" index 5deb694b..074f84bb 100644 --- "a/data_source/exercises/\345\233\260\351\232\276/python/218.exercises/solution.md" +++ "b/data_source/exercises/\345\233\260\351\232\276/python/218.exercises/solution.md" @@ -47,6 +47,58 @@ ## template ```python +import heapq +class Solution: + def getSkyline(self, buildings: List[List[int]]) -> List[List[int]]: + right_heap = [] + height_lst = [] + + ans = [] + + for building in buildings: + left, right, height = building + + while right_heap and right_heap[0][0] < left: + + old_highest = height_lst[-1] + + last_right, last_height = heapq.heappop(right_heap) + height_lst.pop(bisect.bisect_left(height_lst, last_height)) + + new_highest = height_lst[-1] if height_lst else 0 + + if new_highest != old_highest: + if ans and ans[-1][0] == last_right: + ans.pop() + ans.append([last_right, new_highest]) + + old_highest = height_lst[-1] if height_lst else 0 + + bisect.insort_left(height_lst, height) + heapq.heappush(right_heap, (right, height)) + + new_highest = height_lst[-1] + + if new_highest != old_highest: + if ans and ans[-1][0] == left: + ans.pop() + ans.append([left, new_highest]) + + while right_heap: + + old_highest = height_lst[-1] + + last_right, last_height = heapq.heappop(right_heap) + height_lst.pop(bisect.bisect_left(height_lst, last_height)) + + new_highest = height_lst[-1] if height_lst else 0 + + if new_highest != old_highest: + if ans and ans[-1][0] == last_right: + ans.pop() + ans.append([last_right, new_highest]) + + return ans ``` diff --git "a/data_source/exercises/\345\233\260\351\232\276/python/224.exercises/solution.md" "b/data_source/exercises/\345\233\260\351\232\276/python/224.exercises/solution.md" index c6d9e025..5ae4901d 100644 --- "a/data_source/exercises/\345\233\260\351\232\276/python/224.exercises/solution.md" +++ "b/data_source/exercises/\345\233\260\351\232\276/python/224.exercises/solution.md" @@ -39,7 +39,33 @@ ## template ```python - +class Solution: + def calculate(self, s: str) -> int: + s = s.replace(" ", "") + n = len(s) + sign = 1 + stack = [sign] + i = sumS = 0 + while i < n: + if s[i] == "(": + stack.append(sign) + i += 1 + elif s[i] == ")": + stack.pop() + i += 1 + elif s[i] == "+": + sign = stack[-1] + i += 1 + elif s[i] == "-": + sign = -stack[-1] + i += 1 + else: + num = 0 + while i < n and s[i].isdigit(): + num = num * 10 + int(s[i]) + i += 1 + sumS += sign * num + return sumS ``` diff --git "a/data_source/exercises/\345\233\260\351\232\276/python/233.exercises/solution.md" "b/data_source/exercises/\345\233\260\351\232\276/python/233.exercises/solution.md" index 12ace475..02648141 100644 --- "a/data_source/exercises/\345\233\260\351\232\276/python/233.exercises/solution.md" +++ "b/data_source/exercises/\345\233\260\351\232\276/python/233.exercises/solution.md" @@ -30,7 +30,15 @@ ## template ```python - +class Solution: + def countDigitOne(self, n: int) -> int: + res, i = 0, 1 + while i <= n: + res += n // (i * 10) * i + x = (n // i) % 10 + res += i if x > 1 else (n % i + 1) * x + i *= 10 + return res ``` diff --git "a/data_source/exercises/\345\233\260\351\232\276/python/239.exercises/solution.md" "b/data_source/exercises/\345\233\260\351\232\276/python/239.exercises/solution.md" index 4b5a61eb..a2c1489a 100644 --- "a/data_source/exercises/\345\233\260\351\232\276/python/239.exercises/solution.md" +++ "b/data_source/exercises/\345\233\260\351\232\276/python/239.exercises/solution.md" @@ -63,7 +63,24 @@ ## template ```python - +class Solution(object): + def maxSlidingWindow(self, nums, k): + """ + :type nums: List[int] + :type k: int + :rtype: List[int] + """ + if len(nums) == 0: + return [] + if k == 1: + return nums + + res = [] + res.append(max(nums[:k])) + for i in range(1, len(nums) - k + 1): + m = max(nums[i : i + k]) + res.append(m) + return res ``` diff --git "a/data_source/exercises/\345\233\260\351\232\276/python/248.exercises/config.json" "b/data_source/exercises/\345\233\260\351\232\276/python/248.exercises/config.json" deleted file mode 100644 index 0fdcbcb2..00000000 --- "a/data_source/exercises/\345\233\260\351\232\276/python/248.exercises/config.json" +++ /dev/null @@ -1,10 +0,0 @@ -{ - "node_id": "dailycode-f22ef4a76d274cf3a86b0a39ca633ad3", - "keywords": [], - "children": [], - "keywords_must": [], - "keywords_forbid": [], - "export": [ - "solution.json" - ] -} \ No newline at end of file diff --git "a/data_source/exercises/\345\233\260\351\232\276/python/248.exercises/solution.json" "b/data_source/exercises/\345\233\260\351\232\276/python/248.exercises/solution.json" deleted file mode 100644 index 7e0f96f6..00000000 --- "a/data_source/exercises/\345\233\260\351\232\276/python/248.exercises/solution.json" +++ /dev/null @@ -1,7 +0,0 @@ -{ - "type": "code_options", - "source": "solution.md", - "exercise_id": "c9904f069c824f5faaffaf2fed29eb56", - "author": "csdn.net", - "keywords": "递归,数组,字符串" -} \ No newline at end of file diff --git "a/data_source/exercises/\345\233\260\351\232\276/python/248.exercises/solution.md" "b/data_source/exercises/\345\233\260\351\232\276/python/248.exercises/solution.md" deleted file mode 100644 index 6037f7be..00000000 --- "a/data_source/exercises/\345\233\260\351\232\276/python/248.exercises/solution.md" +++ /dev/null @@ -1,36 +0,0 @@ -# 中心对称数 III - - - -## template - -```python - - -``` - -## 答案 - -```python - -``` - -## 选项 - -### A - -```python - -``` - -### B - -```python - -``` - -### C - -```python - -``` \ No newline at end of file diff --git "a/data_source/exercises/\345\233\260\351\232\276/python/262.exercises/config.json" "b/data_source/exercises/\345\233\260\351\232\276/python/262.exercises/config.json" deleted file mode 100644 index 4acebd14..00000000 --- "a/data_source/exercises/\345\233\260\351\232\276/python/262.exercises/config.json" +++ /dev/null @@ -1,10 +0,0 @@ -{ - "node_id": "dailycode-c301e89460c74758ad4e74620f28f32d", - "keywords": [], - "children": [], - "keywords_must": [], - "keywords_forbid": [], - "export": [ - "solution.json" - ] -} \ No newline at end of file diff --git "a/data_source/exercises/\345\233\260\351\232\276/python/262.exercises/solution.json" "b/data_source/exercises/\345\233\260\351\232\276/python/262.exercises/solution.json" deleted file mode 100644 index 0e10fa68..00000000 --- "a/data_source/exercises/\345\233\260\351\232\276/python/262.exercises/solution.json" +++ /dev/null @@ -1,7 +0,0 @@ -{ - "type": "code_options", - "source": "solution.md", - "exercise_id": "629ae5169ce149db9bb2c40d4f8a293a", - "author": "csdn.net", - "keywords": "数据库" -} \ No newline at end of file diff --git "a/data_source/exercises/\345\233\260\351\232\276/python/262.exercises/solution.md" "b/data_source/exercises/\345\233\260\351\232\276/python/262.exercises/solution.md" deleted file mode 100644 index d479bdc9..00000000 --- "a/data_source/exercises/\345\233\260\351\232\276/python/262.exercises/solution.md" +++ /dev/null @@ -1,146 +0,0 @@ -# 行程和用户 - -表:Trips
--+-------------+----------+ -| Column Name | Type | -+-------------+----------+ -| Id | int | -| Client_Id | int | -| Driver_Id | int | -| City_Id | int | -| Status | enum | -| Request_at | date | -+-------------+----------+ -Id 是这张表的主键。 -这张表中存所有出租车的行程信息。每段行程有唯一 Id ,其中 Client_Id 和 Driver_Id 是 Users 表中 Users_Id 的外键。 -Status 是一个表示行程状态的枚举类型,枚举成员为(‘completed’, ‘cancelled_by_driver’, ‘cancelled_by_client’) 。 -- -
- -
表:Users
-+-------------+----------+ -| Column Name | Type | -+-------------+----------+ -| Users_Id | int | -| Banned | enum | -| Role | enum | -+-------------+----------+ -Users_Id 是这张表的主键。 -这张表中存所有用户,每个用户都有一个唯一的 Users_Id ,Role 是一个表示用户身份的枚举类型,枚举成员为 (‘client’, ‘driver’, ‘partner’) 。 -Banned 是一个表示用户是否被禁止的枚举类型,枚举成员为 (‘Yes’, ‘No’) 。 -- -
- -
写一段 SQL 语句查出 "2013-10-01"
至 "2013-10-03"
期间非禁止用户(乘客和司机都必须未被禁止)的取消率。非禁止用户即 Banned 为 No 的用户,禁止用户即 Banned 为 Yes 的用户。
取消率 的计算方式如下:(被司机或乘客取消的非禁止用户生成的订单数量) / (非禁止用户生成的订单总数)。
- -返回结果表中的数据可以按任意顺序组织。其中取消率 Cancellation Rate
需要四舍五入保留 两位小数 。
- -
查询结果格式如下例所示:
- --Trips 表: -+----+-----------+-----------+---------+---------------------+------------+ -| Id | Client_Id | Driver_Id | City_Id | Status | Request_at | -+----+-----------+-----------+---------+---------------------+------------+ -| 1 | 1 | 10 | 1 | completed | 2013-10-01 | -| 2 | 2 | 11 | 1 | cancelled_by_driver | 2013-10-01 | -| 3 | 3 | 12 | 6 | completed | 2013-10-01 | -| 4 | 4 | 13 | 6 | cancelled_by_client | 2013-10-01 | -| 5 | 1 | 10 | 1 | completed | 2013-10-02 | -| 6 | 2 | 11 | 6 | completed | 2013-10-02 | -| 7 | 3 | 12 | 6 | completed | 2013-10-02 | -| 8 | 2 | 12 | 12 | completed | 2013-10-03 | -| 9 | 3 | 10 | 12 | completed | 2013-10-03 | -| 10 | 4 | 13 | 12 | cancelled_by_driver | 2013-10-03 | -+----+-----------+-----------+---------+---------------------+------------+ - -Users 表: -+----------+--------+--------+ -| Users_Id | Banned | Role | -+----------+--------+--------+ -| 1 | No | client | -| 2 | Yes | client | -| 3 | No | client | -| 4 | No | client | -| 10 | No | driver | -| 11 | No | driver | -| 12 | No | driver | -| 13 | No | driver | -+----------+--------+--------+ - -Result 表: -+------------+-------------------+ -| Day | Cancellation Rate | -+------------+-------------------+ -| 2013-10-01 | 0.33 | -| 2013-10-02 | 0.00 | -| 2013-10-03 | 0.50 | -+------------+-------------------+ - -2013-10-01: - - 共有 4 条请求,其中 2 条取消。 - - 然而,Id=2 的请求是由禁止用户(User_Id=2)发出的,所以计算时应当忽略它。 - - 因此,总共有 3 条非禁止请求参与计算,其中 1 条取消。 - - 取消率为 (1 / 3) = 0.33 -2013-10-02: - - 共有 3 条请求,其中 0 条取消。 - - 然而,Id=6 的请求是由禁止用户发出的,所以计算时应当忽略它。 - - 因此,总共有 2 条非禁止请求参与计算,其中 0 条取消。 - - 取消率为 (0 / 2) = 0.00 -2013-10-03: - - 共有 3 条请求,其中 1 条取消。 - - 然而,Id=8 的请求是由禁止用户发出的,所以计算时应当忽略它。 - - 因此,总共有 2 条非禁止请求参与计算,其中 1 条取消。 - - 取消率为 (1 / 2) = 0.50 --
3
```python
-
+class Solution:
+ def maxNumber(self, nums1: List[int], nums2: List[int], k: int) -> List[int]:
+ def pick_max(nums, k):
+ stack = []
+ drop = len(nums) - k
+ for num in nums:
+ while drop and stack and stack[-1] < num:
+ stack.pop()
+ drop -= 1
+ stack.append(num)
+ return stack[:k]
+
+ def merge(A, B):
+ lst = []
+ while A or B:
+ bigger = A if A > B else B
+ lst.append(bigger[0])
+ bigger.pop(0)
+ return lst
+
+ return max(
+ merge(pick_max(nums1, i), pick_max(nums2, k - i))
+ for i in range(k + 1)
+ if i <= len(nums1) and k - i <= len(nums2)
+ )
```
## 答案
diff --git "a/data_source/exercises/\345\233\260\351\232\276/python/327.exercises/solution.md" "b/data_source/exercises/\345\233\260\351\232\276/python/327.exercises/solution.md"
index 67e6efe1..bc77c49a 100644
--- "a/data_source/exercises/\345\233\260\351\232\276/python/327.exercises/solution.md"
+++ "b/data_source/exercises/\345\233\260\351\232\276/python/327.exercises/solution.md"
@@ -36,6 +36,58 @@
```python
+class Solution:
+ def countRangeSum(self, nums: List[int], lower: int, upper: int) -> int:
+
+ prefix = [0]
+ last = 0
+ for num in nums:
+ last += num
+ prefix.append(last)
+
+ print(prefix)
+
+ def count(pp, left, right):
+
+ if left == right:
+ return 0
+ else:
+ mid = (left + right) // 2
+
+ ans = count(pp, left, mid) + count(pp, mid + 1, right)
+
+ i1, i2, i3 = left, mid + 1, mid + 1
+ while i1 <= mid:
+ while i2 <= right and pp[i2] - pp[i1] < lower:
+ i2 += 1
+ while i3 <= right and pp[i3] - pp[i1] <= upper:
+ i3 += 1
+ ans += i3 - i2
+ i1 += 1
+
+ result = []
+ i1, i2 = left, mid + 1
+ while i1 <= mid and i2 <= right:
+ if pp[i1] <= pp[i2]:
+ result.append(pp[i1])
+ i1 += 1
+ else:
+ result.append(pp[i2])
+ i2 += 1
+ while i1 <= mid:
+ result.append(pp[i1])
+ i1 += 1
+ while i2 <= right:
+ result.append(pp[i2])
+ i2 += 1
+
+ for i in range(len(result)):
+ pp[i + left] = result[i]
+
+ return ans
+
+ return count(prefix, 0, len(prefix) - 1)
+
```
diff --git "a/data_source/exercises/\345\233\260\351\232\276/python/329.exercises/solution.md" "b/data_source/exercises/\345\233\260\351\232\276/python/329.exercises/solution.md"
index 3e5401a8..253823f3 100644
--- "a/data_source/exercises/\345\233\260\351\232\276/python/329.exercises/solution.md"
+++ "b/data_source/exercises/\345\233\260\351\232\276/python/329.exercises/solution.md"
@@ -44,6 +44,38 @@
```python
+class Solution:
+ def longestIncreasingPath(self, matrix):
+ """
+ :type matrix: List[List[int]]
+ :rtype: int
+ """
+ a = len(matrix)
+ dic = {}
+ nums_max = 1
+ if a == 0:
+ nums_max = 0
+ else:
+ b = len(matrix[0])
+ for i in range(a):
+ for j in range(b):
+ dic[(i,j)] = matrix[i][j]
+ v = dic.keys()
+ nums1 = [[1 for i in range(b)] for j in range(a)]
+ dic = sorted(dic.items(),key = lambda x:x[1])
+ for k in dic:
+ i = k[0][0]
+ j = k[0][1]
+ if (i+1,j) in v and matrix[i+1][j]表1: Person
+-------------+---------+ -| 列名 | 类型 | -+-------------+---------+ -| PersonId | int | -| FirstName | varchar | -| LastName | varchar | -+-------------+---------+ -PersonId 是上表主键 -- -
表2: Address
+-------------+---------+ -| 列名 | 类型 | -+-------------+---------+ -| AddressId | int | -| PersonId | int | -| City | varchar | -| State | varchar | -+-------------+---------+ -AddressId 是上表主键 -- -
- -
编写一个 SQL 查询,满足条件:无论 person 是否有地址信息,都需要基于上述两表提供 person 的以下信息:
- -- -
FirstName, LastName, City, State -- - -## template - -```python - - -``` - -## 答案 - -```python - -``` - -## 选项 - -### A - -```python - -``` - -### B - -```python - -``` - -### C - -```python - -``` \ No newline at end of file diff --git "a/data_source/exercises/\347\256\200\345\215\225/python/176.exercises/config.json" "b/data_source/exercises/\347\256\200\345\215\225/python/176.exercises/config.json" deleted file mode 100644 index af2dbb0d..00000000 --- "a/data_source/exercises/\347\256\200\345\215\225/python/176.exercises/config.json" +++ /dev/null @@ -1,10 +0,0 @@ -{ - "node_id": "dailycode-d3c479c2622c447687e3fb7e15de1ea4", - "keywords": [], - "children": [], - "keywords_must": [], - "keywords_forbid": [], - "export": [ - "solution.json" - ] -} \ No newline at end of file diff --git "a/data_source/exercises/\347\256\200\345\215\225/python/176.exercises/solution.json" "b/data_source/exercises/\347\256\200\345\215\225/python/176.exercises/solution.json" deleted file mode 100644 index f34f2fdb..00000000 --- "a/data_source/exercises/\347\256\200\345\215\225/python/176.exercises/solution.json" +++ /dev/null @@ -1,7 +0,0 @@ -{ - "type": "code_options", - "source": "solution.md", - "exercise_id": "57eda2ec9e414abe985bfab8206388ff", - "author": "csdn.net", - "keywords": "数据库" -} \ No newline at end of file diff --git "a/data_source/exercises/\347\256\200\345\215\225/python/176.exercises/solution.md" "b/data_source/exercises/\347\256\200\345\215\225/python/176.exercises/solution.md" deleted file mode 100644 index 75d2f2ef..00000000 --- "a/data_source/exercises/\347\256\200\345\215\225/python/176.exercises/solution.md" +++ /dev/null @@ -1,55 +0,0 @@ -# 第二高的薪水 - -
编写一个 SQL 查询,获取 Employee
表中第二高的薪水(Salary) 。
+----+--------+ -| Id | Salary | -+----+--------+ -| 1 | 100 | -| 2 | 200 | -| 3 | 300 | -+----+--------+ -- -
例如上述 Employee
表,SQL查询应该返回 200
作为第二高的薪水。如果不存在第二高的薪水,那么查询应返回 null
。
+---------------------+ -| SecondHighestSalary | -+---------------------+ -| 200 | -+---------------------+ -- - -## template - -```python - - -``` - -## 答案 - -```python - -``` - -## 选项 - -### A - -```python - -``` - -### B - -```python - -``` - -### C - -```python - -``` \ No newline at end of file diff --git "a/data_source/exercises/\347\256\200\345\215\225/python/181.exercises/config.json" "b/data_source/exercises/\347\256\200\345\215\225/python/181.exercises/config.json" deleted file mode 100644 index 2963041b..00000000 --- "a/data_source/exercises/\347\256\200\345\215\225/python/181.exercises/config.json" +++ /dev/null @@ -1,10 +0,0 @@ -{ - "node_id": "dailycode-8df5d16990f1484597a1e6052c2eb5c1", - "keywords": [], - "children": [], - "keywords_must": [], - "keywords_forbid": [], - "export": [ - "solution.json" - ] -} \ No newline at end of file diff --git "a/data_source/exercises/\347\256\200\345\215\225/python/181.exercises/solution.json" "b/data_source/exercises/\347\256\200\345\215\225/python/181.exercises/solution.json" deleted file mode 100644 index 7c9aaedf..00000000 --- "a/data_source/exercises/\347\256\200\345\215\225/python/181.exercises/solution.json" +++ /dev/null @@ -1,7 +0,0 @@ -{ - "type": "code_options", - "source": "solution.md", - "exercise_id": "1a6eaa6d11b14d6890597700888efd43", - "author": "csdn.net", - "keywords": "数据库" -} \ No newline at end of file diff --git "a/data_source/exercises/\347\256\200\345\215\225/python/181.exercises/solution.md" "b/data_source/exercises/\347\256\200\345\215\225/python/181.exercises/solution.md" deleted file mode 100644 index 3357daf4..00000000 --- "a/data_source/exercises/\347\256\200\345\215\225/python/181.exercises/solution.md" +++ /dev/null @@ -1,56 +0,0 @@ -# 超过经理收入的员工 - -
Employee
表包含所有员工,他们的经理也属于员工。每个员工都有一个 Id,此外还有一列对应员工的经理的 Id。
+----+-------+--------+-----------+ -| Id | Name | Salary | ManagerId | -+----+-------+--------+-----------+ -| 1 | Joe | 70000 | 3 | -| 2 | Henry | 80000 | 4 | -| 3 | Sam | 60000 | NULL | -| 4 | Max | 90000 | NULL | -+----+-------+--------+-----------+ -- -
给定 Employee
表,编写一个 SQL 查询,该查询可以获取收入超过他们经理的员工的姓名。在上面的表格中,Joe 是唯一一个收入超过他的经理的员工。
+----------+ -| Employee | -+----------+ -| Joe | -+----------+ -- - -## template - -```python - - -``` - -## 答案 - -```python - -``` - -## 选项 - -### A - -```python - -``` - -### B - -```python - -``` - -### C - -```python - -``` \ No newline at end of file diff --git "a/data_source/exercises/\347\256\200\345\215\225/python/182.exercises/config.json" "b/data_source/exercises/\347\256\200\345\215\225/python/182.exercises/config.json" deleted file mode 100644 index 4858e6c4..00000000 --- "a/data_source/exercises/\347\256\200\345\215\225/python/182.exercises/config.json" +++ /dev/null @@ -1,10 +0,0 @@ -{ - "node_id": "dailycode-d13ab8edfde04e129b31e4efb3052cd2", - "keywords": [], - "children": [], - "keywords_must": [], - "keywords_forbid": [], - "export": [ - "solution.json" - ] -} \ No newline at end of file diff --git "a/data_source/exercises/\347\256\200\345\215\225/python/182.exercises/solution.json" "b/data_source/exercises/\347\256\200\345\215\225/python/182.exercises/solution.json" deleted file mode 100644 index b55f1e7b..00000000 --- "a/data_source/exercises/\347\256\200\345\215\225/python/182.exercises/solution.json" +++ /dev/null @@ -1,7 +0,0 @@ -{ - "type": "code_options", - "source": "solution.md", - "exercise_id": "0535dc76a70c49b78cfaebd47b24d8c5", - "author": "csdn.net", - "keywords": "数据库" -} \ No newline at end of file diff --git "a/data_source/exercises/\347\256\200\345\215\225/python/182.exercises/solution.md" "b/data_source/exercises/\347\256\200\345\215\225/python/182.exercises/solution.md" deleted file mode 100644 index aed765db..00000000 --- "a/data_source/exercises/\347\256\200\345\215\225/python/182.exercises/solution.md" +++ /dev/null @@ -1,59 +0,0 @@ -# 查找重复的电子邮箱 - -
编写一个 SQL 查询,查找 Person
表中所有重复的电子邮箱。
示例:
- -+----+---------+ -| Id | Email | -+----+---------+ -| 1 | a@b.com | -| 2 | c@d.com | -| 3 | a@b.com | -+----+---------+ -- -
根据以上输入,你的查询应返回以下结果:
- -+---------+ -| Email | -+---------+ -| a@b.com | -+---------+ -- -
说明:所有电子邮箱都是小写字母。
- - -## template - -```python - - -``` - -## 答案 - -```python - -``` - -## 选项 - -### A - -```python - -``` - -### B - -```python - -``` - -### C - -```python - -``` \ No newline at end of file diff --git "a/data_source/exercises/\347\256\200\345\215\225/python/183.exercises/config.json" "b/data_source/exercises/\347\256\200\345\215\225/python/183.exercises/config.json" deleted file mode 100644 index 54e05f51..00000000 --- "a/data_source/exercises/\347\256\200\345\215\225/python/183.exercises/config.json" +++ /dev/null @@ -1,10 +0,0 @@ -{ - "node_id": "dailycode-cc84e6279dfd4f20b078317c168abf4f", - "keywords": [], - "children": [], - "keywords_must": [], - "keywords_forbid": [], - "export": [ - "solution.json" - ] -} \ No newline at end of file diff --git "a/data_source/exercises/\347\256\200\345\215\225/python/183.exercises/solution.json" "b/data_source/exercises/\347\256\200\345\215\225/python/183.exercises/solution.json" deleted file mode 100644 index 96e9b586..00000000 --- "a/data_source/exercises/\347\256\200\345\215\225/python/183.exercises/solution.json" +++ /dev/null @@ -1,7 +0,0 @@ -{ - "type": "code_options", - "source": "solution.md", - "exercise_id": "247cd415345b4389829d3232cedd7f59", - "author": "csdn.net", - "keywords": "数据库" -} \ No newline at end of file diff --git "a/data_source/exercises/\347\256\200\345\215\225/python/183.exercises/solution.md" "b/data_source/exercises/\347\256\200\345\215\225/python/183.exercises/solution.md" deleted file mode 100644 index 21833fab..00000000 --- "a/data_source/exercises/\347\256\200\345\215\225/python/183.exercises/solution.md" +++ /dev/null @@ -1,69 +0,0 @@ -# 从不订购的客户 - -某网站包含两个表,Customers
表和 Orders
表。编写一个 SQL 查询,找出所有从不订购任何东西的客户。
Customers
表:
+----+-------+ -| Id | Name | -+----+-------+ -| 1 | Joe | -| 2 | Henry | -| 3 | Sam | -| 4 | Max | -+----+-------+ -- -
Orders
表:
+----+------------+ -| Id | CustomerId | -+----+------------+ -| 1 | 3 | -| 2 | 1 | -+----+------------+ -- -
例如给定上述表格,你的查询应返回:
- -+-----------+ -| Customers | -+-----------+ -| Henry | -| Max | -+-----------+ -- - -## template - -```python - - -``` - -## 答案 - -```python - -``` - -## 选项 - -### A - -```python - -``` - -### B - -```python - -``` - -### C - -```python - -``` \ No newline at end of file diff --git "a/data_source/exercises/\347\256\200\345\215\225/python/190.exercises/solution.md" "b/data_source/exercises/\347\256\200\345\215\225/python/190.exercises/solution.md" index d2bdb2f9..bdda5344 100644 --- "a/data_source/exercises/\347\256\200\345\215\225/python/190.exercises/solution.md" +++ "b/data_source/exercises/\347\256\200\345\215\225/python/190.exercises/solution.md" @@ -43,7 +43,15 @@ ## template ```python - +class Solution: + def reverseBits(self, n: int) -> int: + j = 0 + y = bin(n)[2::] + if len(y) != 32: + j = 32 - len(y) + m = y[::-1] + m = m + "0" * j + return int(m, 2) ``` diff --git "a/data_source/exercises/\347\256\200\345\215\225/python/191.exercises/solution.md" "b/data_source/exercises/\347\256\200\345\215\225/python/191.exercises/solution.md" index d035d863..60507a63 100644 --- "a/data_source/exercises/\347\256\200\345\215\225/python/191.exercises/solution.md" +++ "b/data_source/exercises/\347\256\200\345\215\225/python/191.exercises/solution.md" @@ -59,7 +59,24 @@ ## template ```python - +class Solution(object): + def majorityElement(self, nums): + """ + :type nums: List[int] + :rtype: int + """ + n = len(nums) + if n == 1: + return nums[0] + + dic = {} + for num in nums: + if num in dic.keys(): + dic[num] += 1 + if dic[num] > n / 2: + return num + else: + dic[num] = 1 ``` diff --git "a/data_source/exercises/\347\256\200\345\215\225/python/193.exercises/config.json" "b/data_source/exercises/\347\256\200\345\215\225/python/193.exercises/config.json" deleted file mode 100644 index 9b6790c3..00000000 --- "a/data_source/exercises/\347\256\200\345\215\225/python/193.exercises/config.json" +++ /dev/null @@ -1,10 +0,0 @@ -{ - "node_id": "dailycode-c9d7f91ab5a145a7baeceffb4427d69b", - "keywords": [], - "children": [], - "keywords_must": [], - "keywords_forbid": [], - "export": [ - "solution.json" - ] -} \ No newline at end of file diff --git "a/data_source/exercises/\347\256\200\345\215\225/python/193.exercises/solution.json" "b/data_source/exercises/\347\256\200\345\215\225/python/193.exercises/solution.json" deleted file mode 100644 index d399e692..00000000 --- "a/data_source/exercises/\347\256\200\345\215\225/python/193.exercises/solution.json" +++ /dev/null @@ -1,7 +0,0 @@ -{ - "type": "code_options", - "source": "solution.md", - "exercise_id": "c9c96094632643beb815c338f65b9420", - "author": "csdn.net", - "keywords": "shell" -} \ No newline at end of file diff --git "a/data_source/exercises/\347\256\200\345\215\225/python/193.exercises/solution.md" "b/data_source/exercises/\347\256\200\345\215\225/python/193.exercises/solution.md" deleted file mode 100644 index 52bcc630..00000000 --- "a/data_source/exercises/\347\256\200\345\215\225/python/193.exercises/solution.md" +++ /dev/null @@ -1,60 +0,0 @@ -# 有效电话号码 - -
给定一个包含电话号码列表(一行一个电话号码)的文本文件 file.txt
,写一个单行 bash 脚本输出所有有效的电话号码。
你可以假设一个有效的电话号码必须满足以下两种格式: (xxx) xxx-xxxx 或 xxx-xxx-xxxx。(x 表示一个数字)
- -你也可以假设每行前后没有多余的空格字符。
- -- -
示例:
- -假设 file.txt
内容如下:
-987-123-4567 -123 456 7890 -(123) 456-7890 -- -
你的脚本应当输出下列有效的电话号码:
- --987-123-4567 -(123) 456-7890 -- - -## template - -```python - - -``` - -## 答案 - -```python - -``` - -## 选项 - -### A - -```python - -``` - -### B - -```python - -``` - -### C - -```python - -``` \ No newline at end of file diff --git "a/data_source/exercises/\347\256\200\345\215\225/python/195.exercises/config.json" "b/data_source/exercises/\347\256\200\345\215\225/python/195.exercises/config.json" deleted file mode 100644 index 81d5f6f2..00000000 --- "a/data_source/exercises/\347\256\200\345\215\225/python/195.exercises/config.json" +++ /dev/null @@ -1,10 +0,0 @@ -{ - "node_id": "dailycode-397b53d653ae4c209d619135604a0678", - "keywords": [], - "children": [], - "keywords_must": [], - "keywords_forbid": [], - "export": [ - "solution.json" - ] -} \ No newline at end of file diff --git "a/data_source/exercises/\347\256\200\345\215\225/python/195.exercises/solution.json" "b/data_source/exercises/\347\256\200\345\215\225/python/195.exercises/solution.json" deleted file mode 100644 index 591444b9..00000000 --- "a/data_source/exercises/\347\256\200\345\215\225/python/195.exercises/solution.json" +++ /dev/null @@ -1,7 +0,0 @@ -{ - "type": "code_options", - "source": "solution.md", - "exercise_id": "f9cdb75bc4ad406cb8a4570ced428651", - "author": "csdn.net", - "keywords": "shell" -} \ No newline at end of file diff --git "a/data_source/exercises/\347\256\200\345\215\225/python/195.exercises/solution.md" "b/data_source/exercises/\347\256\200\345\215\225/python/195.exercises/solution.md" deleted file mode 100644 index 7a879473..00000000 --- "a/data_source/exercises/\347\256\200\345\215\225/python/195.exercises/solution.md" +++ /dev/null @@ -1,62 +0,0 @@ -# 第十行 - -
给定一个文本文件 file.txt
,请只打印这个文件中的第十行。
示例:
- -假设 file.txt
有如下内容:
Line 1 -Line 2 -Line 3 -Line 4 -Line 5 -Line 6 -Line 7 -Line 8 -Line 9 -Line 10 -- -
你的脚本应当显示第十行:
- -Line 10 -- -
说明:
-1. 如果文件少于十行,你应当输出什么?
-2. 至少有三种不同的解法,请尝试尽可能多的方法来解题。
编写一个 SQL 查询,来删除 Person
表中所有重复的电子邮箱,重复的邮箱里只保留 Id 最小 的那个。
+----+------------------+ -| Id | Email | -+----+------------------+ -| 1 | john@example.com | -| 2 | bob@example.com | -| 3 | john@example.com | -+----+------------------+ -Id 是这个表的主键。 -- -
例如,在运行你的查询语句之后,上面的 Person
表应返回以下几行:
+----+------------------+ -| Id | Email | -+----+------------------+ -| 1 | john@example.com | -| 2 | bob@example.com | -+----+------------------+ -- -
- -
提示:
- -Person
表。delete
语句。表 Weather
-+---------------+---------+ -| Column Name | Type | -+---------------+---------+ -| id | int | -| recordDate | date | -| temperature | int | -+---------------+---------+ -id 是这个表的主键 -该表包含特定日期的温度信息- -
- -
编写一个 SQL 查询,来查找与之前(昨天的)日期相比温度更高的所有日期的 id
。
返回结果 不要求顺序 。
- -查询结果格式如下例:
- -
-Weather
-+----+------------+-------------+
-| id | recordDate | Temperature |
-+----+------------+-------------+
-| 1 | 2015-01-01 | 10 |
-| 2 | 2015-01-02 | 25 |
-| 3 | 2015-01-03 | 20 |
-| 4 | 2015-01-04 | 30 |
-+----+------------+-------------+
-
-Result table:
-+----+
-| id |
-+----+
-| 2 |
-| 4 |
-+----+
-2015-01-02 的温度比前一天高(10 -> 25)
-2015-01-04 的温度比前一天高(20 -> 30)
-
-