sachinsingh3232 / Hactoberfest

Repository for hacktoberfest 2022
16 stars 184 forks source link

optamized code #258

Open Anshv9616 opened 1 month ago

Anshv9616 commented 1 month ago

Use const string& in the Loop: This avoids unnecessary copies when iterating through the input vector.

String Key Construction: Instead of using a separate variable to create the key, we can directly construct it in a single loop. This is more straightforward and avoids potential confusion.

Reserve Space for the Result: By reserving space for the ans vector, we can reduce the number of reallocations that might occur as we push back results.

Move Semantics: When adding the grouped strings to the result, using move transfers ownership without copying, which can improve performance when dealing with larger strings.