Is Using ChatGPT to Fix My Code Considered Cheating?

0
2
Asked By CuriousCoder42 On

I'm currently working on a data structures and algorithms problem where I needed to reverse an integer. Here's the code I came up with:

```cpp
class Solution {
public:
int reverse(int x) {
if (std::pow(-2,31) < x < 0) {
std::string y = std::to_string(x);
std::reverse(y.begin(), y.end());
x = std::stoi(y);
return -1 * x;
} else if (0 < x < std::pow(2,30)) {
std::string y = std::to_string(x);
std::reverse(y.begin(), y.end());
x = std::stoi(y);
return x;
} else {
return 0;
}
}
};
```

This code is almost correct but didn't meet the standards on the LeetCode site. So, I asked ChatGPT for help to correct some small issues regarding the comparison limits, keeping most of my original structure. I'm wondering, will this be considered cheating?

1 Answer

Answered By CodeConnoisseur89 On

In my opinion, if your task is to reverse an integer, using string manipulation like reversing the string and converting back isn't really solving the problem as intended. The exercise is to implement an integer-reversal method without relying on external functions. It’s like building a tool with just your bare hands, not using pre-made gadgets in the process.

StringReversalNinja -

I see your point, but the problem statement should specify that we can’t use built-in functions. Plus, my approach got accepted on the site, so does that really mean it was wrong?

Related Questions

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.