Original link: https://github.com/yihong0618/gitblog/issues/237
early
Haven’t blogged in a while.
In general, I just tweet what I can express in four pictures and 140 words. Thinking that this may exceed this length, I will write it here.
Of course, there is a brief summary. Thanks for the two-way link of GitHub Issues. I only need #205. You can directly see the related article in the previous article – “How the Likou Program Works”, I also read it yesterday. once again haha. So the format of this one will be the same as the previous one.
cause
Recently, on a whim, I decided to brush a few questions . The last time I brushed the questions was 3 years ago.
In the process of brushing the questions, I felt my own inadequacy. After writing the code, submit it directly, and the result is often wrong. I also found that LeetCode has a first test function, and you need to write test cases yourself.
After compiling a few times, I suddenly thought, why can’t I use the official test case? It’s not more convenient that way. I searched and found that there is no, and this requirement is still mentioned by someone
- https://leetcode.com/discuss/general-discussion/635684/option-to-view-all-the-testcases
- https://www.quora.com/How-do-I-get-all-the-test-cases-of-problems-posted-on-LeetCode/answer/Vipin-Sharma-83
So can I get the test case using the method of my previous article?
explore
- I ran the previous process and found that LeetCode has changed some things and added a little security measures, but the above method is still available
- Observe the files under /mnt dir,
data.in
is the strangest, so can we open it? - No problem at all, the content inside is the test case… It’s easy to get it, and it can be seen in the interface. We can directly print it so that we can see it in stdout
keep exploring
- So can I write a script to take all these tests and generate all the test cases directly? It looks simple, but it’s actually planted
- Because LeetCode’s test is very rigorous, for later tests, such as strings, it will use a very long string, len(s) > 500000
print
can’t be typed at all, LeetCode will only intercept the former, and use...
instead of - If the whole test is too long, the last part will also be cut off and replaced with how many characters are left, as shown in the figure
- Try to compress the string with
zlib compress + base64
, the same failure, there is a little effect - Continue to try to use
urllib.request.urlopen
to senddata.in
? No, this docker intranet is unreachable - Is there any other way? Yes, collect long strings -> get them in n times -> save them at the end. However, it is too troublesome for ordinary friends who brush the questions and it is meaningless. Students who are interested can try it by themselves.
what about the meaning
- Don’t want to submit multiple times, I can create a small account, get the test for the first time, and then copy and paste it into the test case, which can ensure that most of the tests are OK.
- After the local test is passed, it is OK to submit it, and you don’t need to write your own tests that conform to LeetCode.
- Today I used this method to get the daily question hahaha
- Weekly matches seem to be useful
Revelation
- Most of the friends who do similar business also started a solution with docker. Be careful. If users are curious, they will get a lot of information from you, even reverse engineering is not necessary. There is also the problem of docker escape that must be careful. LeetCode’s ability to be safe does not mean that all companies can do it.
- I will write more tests myself
- Writing code, researching the principles behind it, and exploring the unknown are much more interesting than brushing the questions. Every time I brush the questions, I end up going astray. . .
- There’s a reason why LeetCode doesn’t publish all the tests, and this time I get it
- In fact, you can also get some limitations of LeetCode setting in this way, you can explore by yourself~
- In fact, the same is true for other languages. I have run through go, and you can use the programming language you are used to testing.
This article is reprinted from: https://github.com/yihong0618/gitblog/issues/237
This site is for inclusion only, and the copyright belongs to the original author.