Merge common algorithm questions (1)

Source: Internet
Author: User

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

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.