Such a shitty problem


  • 134

    The description is not clear not all unless you click on the hint. What's the point of testing all the "+-1" or "-+1" without any input spec nor any situation where input is obtained.


  • 0
    H
    This post is deleted!

  • 1
    I

    It is not a "shitty" problem and actually this is quite a normal question in interview. Implementation of such functions are often asked by companies who are doing system level programming. However, you can definitely ask questions about the requirements.

    Also, you can have a look at the c function api doc:
    http://www.cplusplus.com/reference/cstdlib/atoi/

    This will make the problem clearer.


  • 7
    V

    Problem is though, in an actual interview you can ask for clarification but on leetcode? Duh.


  • 0
    P

    I tried 10 times and finally succeed. Test cases are very very......


  • 0
    P

    I agree I had to create a ugly solution based on the test case that was failing but I understand the point too for the test cases.
    In short not too excited with this one.

    class Solution(object):
        def myAtoi(self, str):
            """
            :type str: str
            :rtype: int
            """
            d = {'9': 9, '3': 3, '7': 7, '4': 4, '6': 6, '0': 0, '1': 1, '2': 2, '8': 8, '5': 5}
            num = False
            neg = False
            result = 0
            pos = False
            for i in str:
                if i==" ":
                    if (neg or pos) and not num:
                        return 0
                    if num:
                        break
                elif i == "-":
                    if neg:
                        return 0 
                    neg = True
                elif i == "+":
                    if pos:
                        return 0 
                    pos = True
                elif i in d:
                    result = result * 10 + d[i]
                    num = True
                else:
                    break
            if neg and pos:
                return 0
            if num:
                result = result*(-1 if neg else 1)
                if result > (2**31-1):
                    result = (2**31-1)
                if result < -(2**31):
                    result = -(2**31)
                return result
            return 0
            ```

  • 3

    I believe that :

    if (your head image == boy || man) {
        you will get downvote;
        such those shitty LeetCoders.
    }
    

    Edit:

    Just a joke, maybe truth :). I don't know why so many people down vote.... lol


  • 1
    F

    To tackle this kind of problem, you may feed it with some special test cases, such as " - 8" and " -8 3 ".
    From the "Expected Answer" given by leetcode, you will learn that the white spaces are only allowed in the beginning.


  • 0
    I

    Sure it is, and some of tests are ....


  • 3
    R

    can not agree more !
    what's the hell ‘+-2’ ...


  • 1
    I

    I have to say if I design this function, these shitty input will throw an exception directly...


  • 2
    I

    I agree, the whole point of doing leetcode is given enough information and solve the problem. If your input specs are not clear and expect we to solve it trials by trails. It is shitty.

    No instruction is given and expect us to get same answer as expected. That is not how it works. If we are given all sorts of freedom for our own atoi, then why do we still have to fit our function to be exact same as expected?

    PS: giving up attempt " b1351351321351". Why is that not a number and expect to be 0? This question is not about developing your own rule but to find the HIDDEN rule of solution. This is stupid.


  • 0
    C

    Totally agree. SUCH A SHITTY PROBLEM.


  • 0
    H
    This post is deleted!

  • 1
    J

    Why " + 413" should be 0 rather than 413?
    Other traps are somewhat acceptable, but this one? Incredibly shitty.


  • 0
    M

    @Jossome I'm getting that issue too. So stupid. I think the way the hint was phrased, you're only supposed to remove the intial whitespace. Any whitespace after the first non-whitespace character is considered an error.


  • 0
    X

    I agree with this is shitty!


  • 0
    D

    @Jossome Did you find an answer why "+ 413" is discarded?


  • 0
    D

    @realinput Did you find an answer why +-2 should be 0?


Log in to reply
 

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