Does anyone face problem like me? I found that when I tried to write two pointer, I am very confused and I struggle with my code for very long time. Sometimes, I easily bugged. How can I improve this?
# | User | Rating |
---|---|---|
1 | tourist | 3803 |
2 | Benq | 3783 |
3 | Radewoosh | 3602 |
4 | maroonrk | 3575 |
5 | fantasy | 3526 |
6 | ko_osaga | 3500 |
7 | ksun48 | 3491 |
8 | Um_nik | 3486 |
9 | jiangly | 3474 |
10 | orzdevinwang | 3461 |
# | User | Contrib. |
---|---|---|
1 | awoo | 180 |
2 | -is-this-fft- | 177 |
3 | nor | 169 |
4 | Um_nik | 168 |
5 | SecondThread | 164 |
6 | maroonrk | 163 |
7 | adamant | 161 |
8 | kostka | 160 |
9 | YouKn0wWho | 158 |
10 | errorgorn | 153 |
Does anyone face problem like me? I found that when I tried to write two pointer, I am very confused and I struggle with my code for very long time. Sometimes, I easily bugged. How can I improve this?
Name |
---|
You need to understand monotonocity. Why are we skipping items? Because they are going to be worse than what we are going to get. Easy peasy. When we have rotten apples, you throw them away.
Excuse me.I am a newbie and may I ask you for what the difference between pointers and variables is?
Sorry,my English may not be very good :(
Actually pointer is a variable .
Other variables store data like int, long long, short , char...... , also pointer is a variable which stores address .
But what KaTiWarn asks about is a technique not what i was talking about above. Note : Don't ever say that you are Newbie.
Hope the best for you.
In general, variables are used to store values, while pointers are used to store the memory address of a value. A pointer is a type of variable that holds the memory address of another variable. This allows the pointer to indirectly reference and manipulate the value of the other variable.
For example, if we have an integer variable called "num" with a value of 5, we can use a pointer to store the memory address of "num" and indirectly access and modify its value. This can be useful in certain situations, such as when we want to pass the address of a variable to a function or when we want to dynamically allocate memory for a variable.
Overall, the main difference between pointers and variables is that pointers store memory addresses, while variables store values.
HMMM.
Actually i've solved this problem like this:
Every time i face 2pointers problem i solve it after wasting time in debugging then i watch many codes for the same problems in editorial and LGM codes .
The idea behind this is you should see the standard codes for problems which solvable by 2pointers approach .
Best wishes .
The two pointer algorithm can be difficult because it involves maintaining and updating two pointers, which can be tricky to keep track of. It also requires careful consideration of the conditions and constraints of the problem in order to determine when to move the pointers and how to update them.
To improve your ability to write two pointer algorithms, it may be helpful to practice solving problems with this approach, and to carefully study the solutions to other problems that use the two pointer technique. It may also be helpful to discuss and learn from others who have experience with this algorithm.