In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-30 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)05/31 Report--
The knowledge points of this article "C language Classic sequence Table example Analysis" are not quite understood by most people, so the editor summarizes the following content, detailed content, clear steps, and has a certain reference value. I hope you can get something after reading this article, let's take a look at this "C language Classic sequence Table example Analysis" article.
1. Remove elements
Title:
Train of thought:
Method 1: move the data in turn to overwrite
Start with the first data and iterate through the array in turn, as in example 1. Find the removed element 2 and move the latter data forward to cover it, as shown in the figure:
There is a defect in this method. It is clearly pointed out in the title that the space complexity O (1) is used to solve this problem, and the space complexity of this method is just O (1), which can be solved, but consider it more carefully. When the time complexity is O (N ^ 2) at the worst, when it is all val, it will move nmurl. There is an isometric sequence with a time complexity of O (N ^ 2). This method is not optimal.
Method 2: double pointer 1.0
Traverse the original array in turn to see if it is val, and copy the value that is not val to the new array, the time complexity of this method is O (N), and the space complexity is also O (N), but the title clearly points out that the space complexity is O (1), so this method is not good, but think carefully, if you continue to use this method with double pointers, but do not open another array, can you change it on the original array? Which leads to double pointer 2.0
Method 3: double pointer 2.0
This method is an upgrade on the basis of method 2, which needs to open up an additional array, which can be changed directly. First, define two variables src and dst as the subscript of the array nums, iterate through the src to see if nums [src] is val, if not, assign it to the subscript dst, and then src++,dst++. If nums [src] = nums [dst], just leave the src++,dst still, and finally return the length dst.
The code is as follows:
Int removeElement (int* nums, int numsSize, int val) {int dst=0; int str=0; while (strnums2 [j]) {nums1 [dst--] = Nums1 [I -];} else {nums1 [dst--] = nums2 [j -];}} while (j > = 0) {nums1 [dst--] = Nums2 [j -] }} the above is about the content of the article "C language Classic sequence Table example Analysis". I believe we all have some understanding. I hope the content shared by the editor will be helpful to you. If you want to know more about the relevant knowledge, please follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.