Bug Report for top-k-elements-in-list
Opened this issue · 0 comments
devprabal commented
Bug Report for https://neetcode.io/problems/top-k-elements-in-list
Please describe the bug below and include any steps to reproduce the bug or screenshots if possible.?title=Bug Report for string-encode-and-decode
doesn't compile on the needcode platform, while it complies on my local machine and also on godbolt.org.
class Solution {
public:
string encode(vector<string>& strs) {
string result = "";
for(auto& s: strs) {
result += "#";
result += std::to_string(s.size());
result += "$";
result += s;
}
return result;
}
vector<string> decode(string s) {
vector<string> result;
string ans = "";
string len = "";
bool found_start = false;
int l = 0;
for(int i =0; i < (int)s.length(); i++) {
if(l == 0)
{
if(s[i] == '#') {
found_start = true;
continue;
}
if(s[i] == '$') {
l = atoi(len.c_str());
len.clear();
found_start = false;
if(l == 0) {
result.push_back("");
}
continue;
}
if(found_start) {
len += s[i];
}
}
if(l > 0) {
while(l) {
ans += s[i];
i++;
l--;
}
result.push_back(ans);
ans.clear();
i--;
}
}
return result;
}
};compile logs from neetcode -
main.cpp:56:28: warning: missing terminating ' character
56 | if(s[i] == '
| ^
main.cpp:56:28: error: missing terminating ' character
main.cpp: In member function ‘std::vector<std::__cxx11::basic_string<char> > Solution::decode(std::string)’:
main.cpp:58:26: error: expected primary-expression before ‘readInput’
58 | std::vector<std::string> readInput() {
| ^~~~~~~~~
main.cpp:58:25: error: expected ‘)’ before ‘readInput’
58 | std::vector<std::string> readInput() {
| ^~~~~~~~~~
| )
main.cpp:56:19: note: to match this ‘(’
56 | if(s[i] == '
| ^