ika 7 年之前
父節點
當前提交
bed370eb0a
共有 4 個文件被更改,包括 19 次插入12 次删除
  1. 3 2
      easy/141.js
  2. 4 3
      easy/160.js
  3. 3 2
      easy/190.js
  4. 9 5
      easy/191.js

+ 3 - 2
easy/141.js

@@ -9,8 +9,8 @@
  */
 
 function ListNode(val) {
-    this.val = val;
-    this.next = null;
+    this.val = val
+    this.next = null
 }
 
 /**
@@ -43,6 +43,7 @@ function __main__() {
     n23.next = n2
     n2.next = n22
     n22.next = n23
+    /*eslint no-console: ["error", { allow: ["log"] }] */    
     console.log(hasCycle(n1))
     console.log(hasCycle(n2))
 }

+ 4 - 3
easy/160.js

@@ -9,8 +9,8 @@
  */
 
 function ListNode(val) {
-    this.val = val;
-    this.next = null;
+    this.val = val
+    this.next = null
 }
 
 /**
@@ -43,7 +43,7 @@ var getIntersectionNode = function (headA, headB) {
         curr = curr.next
     }
     return null
-};
+}
 
 function __main__() {
     let n2 = new ListNode(2)
@@ -60,6 +60,7 @@ function __main__() {
     n12.next = n13
     n24.next = n12
     let n3 = new ListNode(3)
+    /*eslint no-console: ["error", { allow: ["log"] }] */
     console.log(getIntersectionNode(n1, n2))
     console.log(getIntersectionNode(n2, n3))
 }

+ 3 - 2
easy/190.js

@@ -14,7 +14,7 @@ var reverseBitsOld = function (n) {
         res += last
     }
     return res >>> 0
-};
+}
 
 // [note] in js, signed -> unsigned: n >>> 0
 var reverseBits = function (n) {
@@ -24,9 +24,10 @@ var reverseBits = function (n) {
         n ^= bit << i
     }
     return n >>> 0
-};
+}
 
 function __main__() {
+    /*eslint no-console: ["error", { allow: ["log"] }] */    
     console.log(reverseBits(4294967295))
     console.log(reverseBits(43261596))
     console.log(reverseBits(1))

+ 9 - 5
easy/191.js

@@ -6,16 +6,20 @@
  */
 var hammingWeightOld = function (n) {
     let res = 0
-    for (let i = 0; i < 32; i++, res += n & 1, n >>= 1) {}
+    for (let i = 0; i < 32; i++) {
+        res += n & 1
+        n >>= 1
+    }
     return res
-};
+}
 
-// simple solution using build-in
+// simple solution using built-in
 var hammingWeight = function (n) {
-    return (n).toString(2).replace(/0/g, '').length;
-};
+    return (n).toString(2).replace(/0/g, '').length
+}
 
 function __main__() {
+    /*eslint no-console: ["error", { allow: ["log"] }] */
     console.log(hammingWeight(0xFFFFFFFF))
     console.log(hammingWeightOld(0xFFFFFFFF))
 }