Date:5/25/2022
Study Plan and Problem Number: 代码随想录(贪心算法)12-17
Problem 1: 452. Minimum Number of Arrows to Burst Ballons
Syntax:
- Pass by reference:
- "What is surprising is that passing a complex object by reference is almost 40% faster than passing by value. Only ints and smaller objects should be passed by value, because it's cheaper to copy them than to take the dereferencing hit within the function. In C, all variables must be declared at the top of a function."
- In this question, I utilize the exact same and proper algorithm to operate the program, but the difference in defining the 'myComp' function for ;std::sorting'. When using passing by value, the program exceeds time limit. However, passing by reference will fasten the program by an astonishing amount. Pics below are the compare and contrast. P1 is passing by reference, and P2 is by copy of value.
Algorithm & Structure:
- It's crucial to know that the underlying structure for vector is regular C-array. When we only want to insert or deal with the first or last element of the structure, we can use list to achieve that. Since the underlying structure for that is LINKED-LIST.
Conclusion:
Next Plan:
种一棵树最好的时机是十年前 其次是现在。