Merge common algorithm questions (1)
Some of the content in this chapter has previously summarized the detailed ideas and steps in the public account, and some may find time to analyze them later. Here we will only list the final implementations, the difficulty level does not matter in sequence, and the algorithm complexity is not guaranteed to be optimal. We will leave it to everyone to think about. Of course, this chapter uses the C # language for coding, you can use a language you are familiar with to implement these algorithms ~
If you have any interesting or unsolved algorithm questions, you can also leave a message to the editor. Let's play with algorithms ~
1. Bubble Sorting
This is the simplest of all algorithms. The implementation method is as follows:
2. Insert sorting
From the sorting algorithm, this algorithm is also relatively simple. The implementation method is as follows:
3. merge the two ordered arrays and ensure that the arrays remain sorted after the merging.
Of course, this algorithm can be completed by using the two sorting methods above, but one of the favorable conditions of the question is that the two arrays are already in an ordered state. Therefore, make good use of this favorable condition, this will make the algorithm more complex. The implementation method is as follows:
4. Two Sum
This question comes from LeetCode. The difficulty level is simple.
The implementation method is as follows:
5. Add Two Numbers
It is also an algorithm question from LeetCode. The difficulty is average.
The implementation method is as follows:
6. Use C # encoding to implement the String. Split () method
This is equivalent to implementing this method in the class library instead of using the method provided by the class library. There are many implementation methods. The recommended method is as follows:
7. Use C # encoding to implement the String. Replace () method
Similar to the above question, it is also the method provided by the implementation class library. StringBuilder is used here, but it is not guaranteed that the method is optimal ~ You can think for yourself:
These algorithms are the main parts of this competition, and the difficulty value is actually not big. It depends on whether you can understand the logic ~
If you want to see updates and more exciting content of this series of articles in the first place, you can scan the following QR code to pay attention to the public number: listen to the wind and rain in the building like a month