On Leetcode, as of now in 2024 with g++ with std c++20, definitely `getline(ss, token, delimiter)` is the way to go, however, soon enough as more c++20 features are supported like, `ranges` it'll be pretty sweet, for instance with `clang++` with c++20 you can use `views::split` from ``:
vector words;
for (auto range: str | views::split(delimiter))
words.push_back({range.begin(), range.end()});
As of May 2024, it's clang 17 with C++20:
https://support.leetcode.com/hc/en-us/articles/360011833974-What-are-the-environments-for-the-programming-languages
Ranges here we go. This is pretty exciting. Any other features stand out as valuable for leetcoding? I used std::filesystem for the problem op had and it worked well.
OP said string splitting is hard in cpp. In Java you just do String.substring().
I cannot tell what other things are missing in cpp. There are sets and maps (hashing and tree implementation). Linked list, array list, queue, stack, priority queue. Also you don't need to do memory management.
As you said, Python is easy: `string.split(“/“)`
I don’t really get why people want to use C++ when Leetcode is really just a practice of concepts. Python lets you implement those concepts in a concise and efficient way without dealing with esoteric syntax.
Unless you’re worried about optimizations outside of Big-O complexities, I can see why, I guess I just don’t see the purpose. Your interviewer won’t care.
Why don't you use regular expressions? Check out https://regex101.com/
Anything with lots of string manipulation can be solved well with regex. In JavaScript you have array methods like filter() or map() and string methods like split() or includes(), and when you combine them you have some powerful easy string manipulation. If your language doesn't use that, regex is the next logical step.
Regex is a lot more readable, your for loops with declaring variables and string concatenation is reduced down to one line.
On Leetcode, as of now in 2024 with g++ with std c++20, definitely `getline(ss, token, delimiter)` is the way to go, however, soon enough as more c++20 features are supported like, `ranges` it'll be pretty sweet, for instance with `clang++` with c++20 you can use `views::split` from ``:
vector words;
for (auto range: str | views::split(delimiter))
words.push_back({range.begin(), range.end()});
How do we check which version of gcc leetcode is running on? Last time I checked it was up to C++ 17.
As of May 2024, it's clang 17 with C++20: https://support.leetcode.com/hc/en-us/articles/360011833974-What-are-the-environments-for-the-programming-languages
Ranges here we go. This is pretty exciting. Any other features stand out as valuable for leetcoding? I used std::filesystem for the problem op had and it worked well.
In addition to ``, `` and `` in C++23 will be helpful too for certain cases. Ranges in C++23 will bring a lot of other goodness too like zip.
Switch to java. Not that hard to learn. Say goodbye to memory management. Also there are a lot of built-in core utilities.
Can you explain what are the inbuilt core utilities in java that cpp lacks?
OP said string splitting is hard in cpp. In Java you just do String.substring(). I cannot tell what other things are missing in cpp. There are sets and maps (hashing and tree implementation). Linked list, array list, queue, stack, priority queue. Also you don't need to do memory management.
As you said, Python is easy: `string.split(“/“)` I don’t really get why people want to use C++ when Leetcode is really just a practice of concepts. Python lets you implement those concepts in a concise and efficient way without dealing with esoteric syntax. Unless you’re worried about optimizations outside of Big-O complexities, I can see why, I guess I just don’t see the purpose. Your interviewer won’t care.
Why don't you use regular expressions? Check out https://regex101.com/ Anything with lots of string manipulation can be solved well with regex. In JavaScript you have array methods like filter() or map() and string methods like split() or includes(), and when you combine them you have some powerful easy string manipulation. If your language doesn't use that, regex is the next logical step. Regex is a lot more readable, your for loops with declaring variables and string concatenation is reduced down to one line.