Skip to content

Instantly share code, notes, and snippets.

😃
I am Clark !

Clark ms314006

😃
I am Clark !
Block or report user

Report or block ms314006

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View Longest Palindromic Substring.js
const isPalindromic = (s) => {
const center = Math.floor(s.length / 2);
for(let i = 0; i <= center; i += 1) {
if(s[i] !== s[s.length - 1 - i]) {
return false;
}
}
return true;
}
View Longest Palindromic Substring.js
const isPalindromic = s => (
s === s.split('').reverse().join('')
);
var longestPalindrome = function(s) {
if (s === '') return '';
let answer = s[0];
for (let i = 0; i < s.length; i+= 1) {
let lastSameStrIndex = s.slice(0, s.length).lastIndexOf(s[i]);
View longestCommonPrefix.js
var longestCommonPrefix = function(strs) {
const firstStr = strs[0];
if (!firstStr) return '';
let condition = true;
let count = -1;
while(condition) {
count += 1;
if (count === firstStr.length) {
View longestCommonPrefix.js
var longestCommonPrefix = function(strs) {
const firstStr = strs[0];
if (!firstStr) return '';
// 其他省略
};
View longestCommonPrefix.js
var longestCommonPrefix = function(strs) {
const firstStr = strs[0]; // (1)
let condition = true;
let count = -1;
while(condition) { // (2)
count += 1;
condition = strs.every(str => (
firstStr[count] === str[count]
));
View .travis with deploy.yml
language: node_js
node_js:
- "8"
install:
- npm install
script:
- npm run clean
- npm run build
deploy:
provider: pages
View .travis.yml
language: node_js
node_js:
- "8"
install:
- npm install
script:
- npm run clean
- npm run build
View Plus One.js
var plusOne = function(digits) {
for(let i = digits.length - 1; i >= 0; i--) {
let lastDigit = digits[i];
if (lastDigit < 9) {
digits[i] += 1;
return digits;
}
digits[i] = 0;
}
return [1, ...digits]
View Plus One.js
var plusOne = function(digits) {
// 總合 join => Number => String => split => map
return String((Number(digits.join('')) + 1)).split('').map(digit => Number(digit));
};
View Maximum Subarray.js
var maxSubArray = function(nums) {
let currentSum = maxSum = nums[0];
for(let i = 1; i < nums.length; i += 1) {
currentSum += nums[i];
if (currentSum < nums[i]) {
currentSum = nums[i];
}
if (currentSum > maxSum) {
You can’t perform that action at this time.