普通视图

发现新文章,点击刷新页面。
今天 — 2026年4月5日首页

JS解法,只需要判断LR的个数是否相等,UD的个数是否相等即可。

作者 chenqming
2019年8月12日 14:10
/**
 * @param {string} moves
 * @return {boolean}
 */
var judgeCircle = function(moves) {
  // 判断左右移动的次数和上下移动的次数是否相等(即 L.count === R.count && U.count === D.count)
  return moves.split('L').length === moves.split('R').length && moves.split('U').length === moves.split('D').length
};
❌
❌