Given a string, find the first non-repeating character in it and return it's index. If it doesn't exist, return -1.

Examples:

s = "leetcode"
return 0.

s = "loveleetcode",
return 2.

s = "",
return -1.

Note: You may assume the string contain only lowercase letters.

Because the number of lowercase letters is 26, it is not necessary to use hash table to record the occurrence number of each letter. Instead it can be solved by bucket sort, i.e. there is 26 buckets which represent 26 lowercase letters, when scanning the letter 'a', the number in the first bucket increase one unit, ..., when scanning the letter 'z', the number in the last bucket increase one unit. For the sake of time saving, I use an array of length 200 to avoid computing the number of bucket(the ascii coding of 'a' is 97, so in this situation, the number of the first bucket is 97 instead of 0), the detailed code demonstrates below:

Implement a RateLimiter Class with an isAllow method. Every request comes in with a unique clientID, deny a request if that client has made more than 100 requests in the past second.

]]>https://discuss.leetcode.com/topic/120626/implement-a-rate-limiterhttps://discuss.leetcode.com/topic/120626/implement-a-rate-limiterWed, 21 Feb 2018 22:38:42 GMTSimple solution that requires iterating through the array once. Keep track of what’s been encountered and push to an output if already encountered.

Complexity Analysis

Reg: O(n)

]]>https://discuss.leetcode.com/topic/120623/atoi-by-pythonhttps://discuss.leetcode.com/topic/120623/atoi-by-pythonWed, 21 Feb 2018 11:07:13 GMTI am new to Javascript, and heard about how LeetCode can help improve my coding skills, so I wanted to give it a try. This is the first problem I have completed, the code doesn't look elegant in my opinion, and I'm sure there is an easier method to resolving the problem... Please reply with feedback!