6
6
"name" : " leetcode-kuro-RnD.ipynb" ,
7
7
"provenance" : [],
8
8
"collapsed_sections" : [],
9
- "authorship_tag" : " ABX9TyMuVBgXIAghJtYeJBqmHikX " ,
9
+ "authorship_tag" : " ABX9TyO0svpuIP2eP4y6EA43A0ZF " ,
10
10
"include_colab_link" : true
11
11
},
12
12
"kernelspec" : {
2721
2721
{
2722
2722
"cell_type" : " code" ,
2723
2723
"metadata" : {
2724
- "id" : " OabIUojIu8f9"
2724
+ "id" : " OabIUojIu8f9" ,
2725
+ "colab" : {
2726
+ "base_uri" : " https://localhost:8080/"
2727
+ },
2728
+ "outputId" : " c5a7b75b-b036-4875-8dd3-f3027225af46"
2725
2729
},
2726
2730
"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 " ,
2729
2736
" \r\n " ,
2730
2737
" # permutations = list((nums[j:][0:k] for j in range(len(nums) - k + 1)))\r\n " ,
2731
2738
" # print(permutations)\r\n " ,
2755
2762
" # print(len(val))\r\n " ,
2756
2763
" # print(val)\r\n " ,
2757
2764
" lists_n+=[val]\r\n " ,
2758
- " print(lists_n)\r\n " ,
2765
+ " print(sorted( lists_n)[0] )\r\n " ,
2759
2766
" \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 "
2769
2776
],
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
+ ]
2772
2789
},
2773
2790
{
2774
2791
"cell_type" : " code" ,
2783
2800
"source" : [
2784
2801
" %pwd"
2785
2802
],
2786
- "execution_count" : 21 ,
2803
+ "execution_count" : null ,
2787
2804
"outputs" : [
2788
2805
{
2789
2806
"output_type" : " execute_result" ,
2814
2831
"source" : [
2815
2832
" cd .. "
2816
2833
],
2817
- "execution_count" : 22 ,
2834
+ "execution_count" : null ,
2818
2835
"outputs" : [
2819
2836
{
2820
2837
"output_type" : " stream" ,
2836
2853
],
2837
2854
"execution_count" : null ,
2838
2855
"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
+ ]
2839
2897
}
2840
2898
]
2841
2899
}
0 commit comments