File tree Expand file tree Collapse file tree 1 file changed +43
-4
lines changed Expand file tree Collapse file tree 1 file changed +43
-4
lines changed Original file line number Diff line number Diff line change 8191
8191
},
8192
8192
{
8193
8193
"cell_type" : " code" ,
8194
- "execution_count" : null ,
8194
+ "execution_count" : 45 ,
8195
8195
"metadata" : {},
8196
- "outputs" : [],
8196
+ "outputs" : [
8197
+ {
8198
+ "name" : " stdout" ,
8199
+ "output_type" : " stream" ,
8200
+ "text" : [
8201
+ " anviaj\n " ,
8202
+ " an\n " ,
8203
+ " anv\n " ,
8204
+ " anvi\n " ,
8205
+ " iaj\n " ,
8206
+ " iaj\n " ,
8207
+ " ['anvi', 'iaj']\n " ,
8208
+ " 4\n "
8209
+ ]
8210
+ }
8211
+ ],
8197
8212
"source" : [
8198
8213
" # https://leetcode.com/problems/longest-substring-without-repeating-characters/\n " ,
8199
8214
" \n " ,
8204
8219
" # s = \"\"\n " ,
8205
8220
" # s = ' '\n " ,
8206
8221
" # s = 'aab'\n " ,
8207
- " s = 'dvdf'\n " ,
8222
+ " # s = 'dvdf'\n " ,
8223
+ " s = 'anviaj'\n " ,
8224
+ " \n " ,
8225
+ " print(s)\n " ,
8208
8226
" \n " ,
8209
8227
" \n " ,
8210
- " \n "
8228
+ " max_sub_str = s[0]\n " ,
8229
+ " max_arr = []\n " ,
8230
+ " \n " ,
8231
+ " for i in range(1,len(s)):\n " ,
8232
+ " if max_sub_str[-1] != s[i] and s[i] not in max_sub_str:\n " ,
8233
+ " max_sub_str+=s[i]\n " ,
8234
+ " print(max_sub_str)\n " ,
8235
+ " else: \n " ,
8236
+ " max_arr.append(max_sub_str)\n " ,
8237
+ " if max_sub_str[-1]!=s[i] : \n " ,
8238
+ " max_sub_str = max_sub_str[-1]+s[i]\n " ,
8239
+ " else:\n " ,
8240
+ " max_sub_str = s[i]\n " ,
8241
+ " if max_arr == [] or max_sub_str not in max_arr:\n " ,
8242
+ " max_arr.append(max_sub_str)\n " ,
8243
+ " \n " ,
8244
+ " print(max_sub_str)\n " ,
8245
+ " print(max_arr)\n " ,
8246
+ " print(len(max(max_arr, key=len)))\n " ,
8247
+ " \n " ,
8248
+ " \n " ,
8249
+ " # current condition : not working \n "
8211
8250
]
8212
8251
}
8213
8252
],
You can’t perform that action at this time.
0 commit comments