{"action":"opened","issue":{"url":"https://api.github.com/repos/Yvette-Chen/LeetCode-daily/issues/4","repository_url":"https://api.github.com/repos/Yvette-Chen/LeetCode-daily","labels_url":"https://api.github.com/repos/Yvette-Chen/LeetCode-daily/issues/4/labels{/name}","comments_url":"https://api.github.com/repos/Yvette-Chen/LeetCode-daily/issues/4/comments","events_url":"https://api.github.com/repos/Yvette-Chen/LeetCode-daily/issues/4/events","html_url":"https://github.com/Yvette-Chen/LeetCode-daily/issues/4","id":175515079,"number":4,"title":"String to Interger","user":{"login":"Yvette-Chen","id":20876318,"avatar_url":"https://avatars.githubusercontent.com/u/20876318?v=3","gravatar_id":"","url":"https://api.github.com/users/Yvette-Chen","html_url":"https://github.com/Yvette-Chen","followers_url":"https://api.github.com/users/Yvette-Chen/followers","following_url":"https://api.github.com/users/Yvette-Chen/following{/other_user}","gists_url":"https://api.github.com/users/Yvette-Chen/gists{/gist_id}","starred_url":"https://api.github.com/users/Yvette-Chen/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Yvette-Chen/subscriptions","organizations_url":"https://api.github.com/users/Yvette-Chen/orgs","repos_url":"https://api.github.com/users/Yvette-Chen/repos","events_url":"https://api.github.com/users/Yvette-Chen/events{/privacy}","received_events_url":"https://api.github.com/users/Yvette-Chen/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2016-09-07T14:20:25Z","updated_at":"2016-09-07T14:20:25Z","closed_at":null,"body":"It looks like a simple question first, but in fact it has so much input that I cannot find out all one time, I learned that we need to think about enough input.\r\n```\r\nclass Solution {\r\npublic:\r\n    int myAtoi(string str) {\r\n        if(str == \"\") return 0;\r\n        int i;\r\n        for (i = 0; str[i] == ' ' && i <str.size(); i++) {}\r\n        if(i != 0 && str[0] == ' ') str.erase(0, i);\r\n        string s1 = str;\r\n        if(s1[0] == '-' || s1[0] == '+') s1.erase(0, 1);\r\n        for(int i = 0; i < s1.size(); i++)\r\n            if(s1[i] < '0' || s1[i] > '9') {\r\n                s1.erase(i, s1.size() - i);\r\n            }\r\n        if(s1.size() > 10 && str[0] == '-') return -2147483648;\r\n        if(s1.size() > 10 && str[0] != '-') return 2147483647;\r\n        if(str[0] == '-' && s1.size() == 10 && s1 > \"2147483648\") return -2147483648;\r\n        if(str[0] != '-' && s1.size() == 10 && str > \"2147483647\") return 2147483647;\r\n        if(str[0] != '-'&& str[0] != '+' && str.size() == 11) return 0;\r\n\r\n        int res = 0, count = 1;\r\n        for(int i = s1.size() - 1; i >= 0; i--) {\r\n            res += (s1[i] - '0') * count;\r\n            count *= 10;\r\n        }\r\n\r\n       if(str[0] == '-') res *= -1;\r\n       return res;\r\n    }\r\n};\r\n```"}}
{"actor":{"display_login":"Yvette-Chen"}}