Skip to content

Commit 82be3d3

Browse files
committed
Created using Colaboratory
1 parent 03289dd commit 82be3d3

File tree

1 file changed

+76
-18
lines changed

1 file changed

+76
-18
lines changed

leetcode_kuro_RnD.ipynb

Lines changed: 76 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"name": "leetcode-kuro-RnD.ipynb",
77
"provenance": [],
88
"collapsed_sections": [],
9-
"authorship_tag": "ABX9TyMuVBgXIAghJtYeJBqmHikX",
9+
"authorship_tag": "ABX9TyO0svpuIP2eP4y6EA43A0ZF",
1010
"include_colab_link": true
1111
},
1212
"kernelspec": {
@@ -2721,11 +2721,18 @@
27212721
{
27222722
"cell_type": "code",
27232723
"metadata": {
2724-
"id": "OabIUojIu8f9"
2724+
"id": "OabIUojIu8f9",
2725+
"colab": {
2726+
"base_uri": "https://localhost:8080/"
2727+
},
2728+
"outputId": "c5a7b75b-b036-4875-8dd3-f3027225af46"
27252729
},
27262730
"source": [
2727-
"nums = [2,4,3,3,5,4,9,6]\r\n",
2728-
"k = 4\r\n",
2731+
"# nums = [2,4,3,3,5,4,9,6]\r\n",
2732+
"# k = 4\r\n",
2733+
"\r\n",
2734+
"nums = [3,5,2,6]\r\n",
2735+
"k = 2\r\n",
27292736
"\r\n",
27302737
"# permutations = list((nums[j:][0:k] for j in range(len(nums) - k + 1)))\r\n",
27312738
"# print(permutations)\r\n",
@@ -2755,20 +2762,30 @@
27552762
" # print(len(val))\r\n",
27562763
" # print(val)\r\n",
27572764
" lists_n+=[val]\r\n",
2758-
"print(lists_n)\r\n",
2765+
"print(sorted(lists_n)[0])\r\n",
27592766
"\r\n",
2760-
"temp_arr = []\r\n",
2761-
"for val in lists_n:\r\n",
2762-
" #print(val[:3])\r\n",
2763-
" for val2 in lists_n:\r\n",
2764-
" #print(val[:3][:] in val2[:])\r\n",
2765-
" print(val[:3][:])\r\n",
2766-
" print(val2[:])\r\n",
2767-
" if val[:3] in val2: temp_arr.append(val2)\r\n",
2768-
" print(temp_arr)\r\n"
2767+
"# temp_arr = []\r\n",
2768+
"# for val in lists_n:\r\n",
2769+
"# #print(val[:3])\r\n",
2770+
"# for val2 in lists_n:\r\n",
2771+
"# #print(val[:3][:] in val2[:])\r\n",
2772+
"# print(val[:3][:])\r\n",
2773+
"# print(val2[:])\r\n",
2774+
"# if val[:3] in val2: temp_arr.append(val2)\r\n",
2775+
"# print(temp_arr)\r\n"
27692776
],
2770-
"execution_count": null,
2771-
"outputs": []
2777+
"execution_count": 29,
2778+
"outputs": [
2779+
{
2780+
"output_type": "stream",
2781+
"text": [
2782+
"[3, 5, 2, 6]\n",
2783+
"[[], [3], [5], [3, 5], [2], [3, 2], [5, 2], [3, 5, 2], [6], [3, 6], [5, 6], [3, 5, 6], [2, 6], [3, 2, 6], [5, 2, 6], [3, 5, 2, 6]]\n",
2784+
"[2, 6]\n"
2785+
],
2786+
"name": "stdout"
2787+
}
2788+
]
27722789
},
27732790
{
27742791
"cell_type": "code",
@@ -2783,7 +2800,7 @@
27832800
"source": [
27842801
"%pwd"
27852802
],
2786-
"execution_count": 21,
2803+
"execution_count": null,
27872804
"outputs": [
27882805
{
27892806
"output_type": "execute_result",
@@ -2814,7 +2831,7 @@
28142831
"source": [
28152832
"cd .. "
28162833
],
2817-
"execution_count": 22,
2834+
"execution_count": null,
28182835
"outputs": [
28192836
{
28202837
"output_type": "stream",
@@ -2836,6 +2853,47 @@
28362853
],
28372854
"execution_count": null,
28382855
"outputs": []
2856+
},
2857+
{
2858+
"cell_type": "code",
2859+
"metadata": {
2860+
"colab": {
2861+
"base_uri": "https://localhost:8080/"
2862+
},
2863+
"id": "--QtRxgD1A9p",
2864+
"outputId": "4f673812-b966-4637-c52d-3b64d89cf777"
2865+
},
2866+
"source": [
2867+
"\n",
2868+
"nums = [3,5,2,6]\n",
2869+
"k = 2\n",
2870+
"\n",
2871+
"nums = [2,4,3,3,5,4,9,6]\n",
2872+
"k = 4\n",
2873+
"\n",
2874+
"#https://leetcode.com/problems/find-the-most-competitive-subsequence/\n",
2875+
"\n",
2876+
"\n",
2877+
"attempts = len(nums) - k\n",
2878+
"stack = []\n",
2879+
"for num in nums:\n",
2880+
" while stack and num < stack[-1] and attempts > 0:\n",
2881+
" stack.pop()\n",
2882+
" attempts -= 1\n",
2883+
" stack.append(num)\n",
2884+
" \n",
2885+
"print(stack[:k])"
2886+
],
2887+
"execution_count": 32,
2888+
"outputs": [
2889+
{
2890+
"output_type": "stream",
2891+
"text": [
2892+
"[2, 3, 3, 4]\n"
2893+
],
2894+
"name": "stdout"
2895+
}
2896+
]
28392897
}
28402898
]
28412899
}

0 commit comments

Comments
 (0)