Why C++ abs(int) function is not working here?

  • 0

    When I use abs(s.size() - t.size()), it seems that it would not return the right value. This leads to fails on test cases like 'teacher', 'teacherly'.

    When I looking at others solutions, one thing I've noticed is nobody was using the abs function here. Is it broken?

  • 2

    No, it is not because of the abs, it is because the type of s.size() is unsigned int, which makes the negative value problematic.

Log in to reply

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.