js regex match all white spaces All In One
const str = `abc xyz ufo`;
// regex to remove spaces
str.replace(/\s/g, '');
//
// regex only letters not spaces
const reg = /^[A-Za-z]+$/;
demo
/**
* @param {string} s
* @return {string}
*/
var replaceSpace = function(s) {
// return s.replaceAll(/ /g, '%20')
// return s.replaceAll(/\s/g, '%20')
// return s.split(' ').join('%20');
let r = '';
for(let c of s) {
r += (c === ' ') ? '%20' : c;
}
return r;
};
https://leetcode.cn/leetbook/read/illustration-of-algorithm/50ywkd/
https://leetcode.cn/submissions/detail/324000591/
LeetCode 经典面试题目清单
初级算法 - 帮助入门
https://leetcode.cn/leetbook/detail/top-interview-questions-easy/
中级算法 - 巩固训练
https://leetcode.cn/leetbook/detail/top-interview-questions-medium/
高级算法 - 提升进阶
https://leetcode.cn/leetbook/detail/top-interview-questions-hard/
refs
©xgqfrms 2012-2020
www.cnblogs.com/xgqfrms 发布文章使用:只允许注册用户才可以访问!
原创文章,版权所有©️xgqfrms, 禁止转载 ️,侵权必究⚠️!