Cool solution. Saved a lot of conditional statements.
easyandme
@easyandme
Posts made by easyandme

RE: A few lines of JavaScript

RE: It is a math question
@StefanPochmann Stefan was asking someone to explain! We don't often see this :)))

RE: Java 1Line Solution via Regex and Stream
JS version
const findWords = (words) => { return words.filter((word) => /^[qwertyuiop]*$^[asdfghjkl]*$^[zxcvbnm]*$/g.test(word.toLowerCase())) }

RE: The solution in JavaScript ...
@mx0910gmail.com Your code can be improved as such:
/** * @param {number} x * @return {number} */ var reverse = function(x) { var r = 0 while (x != 0) { var a = x % 10 x = (x  a) / 10 r = r * 10 + a } if (Math.pow(2, 31) < r  Math.pow(2, 31) > r) return 0 return r };
The way you reverse the integer does not require a flag s

RE: Share my thinking process
@HongxiangWang The biggest rest[i] must have been after a sell operation, so the maximum profit after a sell operation  and in the rest day after this sell (i.e. rest[i])  should be the same as the closest possible sell which is sell[i  1]. Since it's easy to see that sell[i1] <= sell[i], rest[i] <= sell[i] is easy to understand now. Hope my explanation helps.

JS One Liner Regex
/** * @param {string} str * @returns {string} */ const reverseWords = function(str) { return str.trim().replace(/[\s]+/g, ' ').split(' ').reverse().join(' ') };

Javascript ES6 One Line Solution (AC, fast)
/** * @param {number[]} nums * @return {number} */ const containsDuplicate = function(nums) { return !(nums.length === (new Set(nums)).size) }

RE: Java Solution, PreSum + HashMap
@apt275 sum  k means the array elements in between add up to k

RE: Share my O(n) time solution
@apt275 sum  k means the array elements in between add up to k