tangweikun/leetcode

View on GitHub

Showing 323 of 498 total issues

Function isValidSudoku has a Cognitive Complexity of 41 (exceeds 5 allowed). Consider refactoring.
Open

var isValidSudoku = function(board) {
  for (let i = 0; i < 9; i++) {
    const hash = {};
    for (let j = 0; j < 9; j++) {
      const num = board[i][j];
Severity: Minor
Found in src/36-valid-sudoku/index.js - About 6 hrs to fix

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

Function fourSum has a Cognitive Complexity of 30 (exceeds 5 allowed). Consider refactoring.
Open

function fourSum(nums, target) {
  if (nums.length < 4) return [];

  nums.sort((x, y) => x - y);
  const res = [];
Severity: Minor
Found in src/18-4Sum/20210729.js - About 4 hrs to fix

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

Function splitIntoFibonacci has a Cognitive Complexity of 29 (exceeds 5 allowed). Consider refactoring.
Open

var splitIntoFibonacci = function(S) {
  const res = [];
  backtrack(res, 0);

  function backtrack(res, startIndex) {
Severity: Minor
Found in src/842-split-array-into-fibonacci-sequence/index.js - About 4 hrs to fix

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

Function fourSum has a Cognitive Complexity of 29 (exceeds 5 allowed). Consider refactoring.
Open

export const fourSum = (nums, target) => {
  nums.sort((x, y) => x - y);
  let res = [];

  for (let i = 0; i < nums.length - 3; i++) {
Severity: Minor
Found in src/18-4Sum/index.js - About 4 hrs to fix

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

Function queensAttacktheKing has a Cognitive Complexity of 26 (exceeds 5 allowed). Consider refactoring.
Open

var queensAttacktheKing = function(queens, king) {
  let res = [];
  const queensMap = queens.map(arr => String(arr[0]) + String(arr[1]));
  let column = king[0];
  let row = king[1];
Severity: Minor
Found in src/1222-queens-that-can-attack-the-king/index.js - About 3 hrs to fix

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

Function numMagicSquaresInside has a Cognitive Complexity of 24 (exceeds 5 allowed). Consider refactoring.
Open

export function numMagicSquaresInside(grid) {
  let res = 0;
  for (let i = 0; i < grid.length - 2; i++) {
    for (let j = 0; j < grid[0].length - 2; j++) {
      let guard = true;
Severity: Minor
Found in src/840-magic-squares-in-grid/index.js - About 3 hrs to fix

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

Function threeSum has a Cognitive Complexity of 23 (exceeds 5 allowed). Consider refactoring.
Open

function threeSum(nums) {
  if (nums.length < 3) return [];
  nums.sort((x, y) => x - y);
  const res = [];

Severity: Minor
Found in src/15-3Sum/20210729.js - About 3 hrs to fix

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

Function findMedianSortedArrays has a Cognitive Complexity of 23 (exceeds 5 allowed). Consider refactoring.
Open

var findMedianSortedArrays = function(nums1, nums2) {
  while (nums1.length + nums2.length > 2) {
    if (nums1.length === 0) {
      nums2.pop();
      nums2.shift();
Severity: Minor
Found in src/4-median-of-two-sorted-arrays/index.js - About 3 hrs to fix

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

Function queensAttacktheKing has 81 lines of code (exceeds 25 allowed). Consider refactoring.
Open

var queensAttacktheKing = function(queens, king) {
  let res = [];
  const queensMap = queens.map(arr => String(arr[0]) + String(arr[1]));
  let column = king[0];
  let row = king[1];
Severity: Major
Found in src/1222-queens-that-can-attack-the-king/index.js - About 3 hrs to fix

    Function updateMatrix has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring.
    Open

    export const updateMatrix = matrix => {
      let res = [];
      for (let i = 0; i < matrix.length; i++) {
        res.push([]);
      }
    Severity: Minor
    Found in src/542-01-matrix/index.js - About 3 hrs to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Function findMedianSortedArrays has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring.
    Open

    var findMedianSortedArrays = function (nums1, nums2) {
      const len = nums1.length + nums2.length;
      if (len === 1) {
        return ~~nums1[0] + ~~nums2[0];
      }
    Severity: Minor
    Found in src/4-median-of-two-sorted-arrays/20210603.js - About 3 hrs to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Function countServers has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring.
    Open

    var countServers = function (grid) {
      const arrX = [];
      const arrY = [];
      let res = 0;
    
    
    Severity: Minor
    Found in src/1267-count-servers-that-communicate/index.js - About 2 hrs to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Function invalidTransactions has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring.
    Open

    var invalidTransactions = function (transactions) {
      let res = [];
      let map = {};
      // 以名字区分
      for (let t of transactions) {
    Severity: Minor
    Found in src/1169-invalid-transactions/index.js - About 2 hrs to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Function peopleIndexes has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
    Open

    var peopleIndexes = function (favoriteCompanies) {
      let res = [];
      let len = favoriteCompanies.length;
    
      for (let i = 0; i < len; i++) {

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Function threeSum has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
    Open

    export const threeSum = (nums) => {
      nums.sort((a, b) => a - b);
      let res = [];
    
      for (let i = 0; i < nums.length; i++) {
    Severity: Minor
    Found in src/15-3Sum/index.js - About 2 hrs to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Function decodeAtIndex has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
    Open

    var decodeAtIndex = function (S, K) {
      let size = 0;
    
      for (let i = 0; i < S.length; i++) {
        // 计算size
    Severity: Minor
    Found in src/880-decoded-string-at-index/index.js - About 2 hrs to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Function minDominoRotations has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
    Open

    var minDominoRotations = function (A, B) {
      let helper = function (num) {
        let toTop = 0;
        let toBottom = 0;
        for (let i = 0, len = A.length; i < len; ++i) {
    Severity: Minor
    Found in src/1007-minimum-domino-rotations-for-equal-row/index.js - About 2 hrs to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Function largestTimeFromDigits has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
    Open

    var largestTimeFromDigits = function(A) {
      let res = -1;
      for (let i = 0; i < 4; i++) {
        for (let j = 0; j < 4; j++) {
          for (let k = 0; k < 4; k++) {
    Severity: Minor
    Found in src/949-largest-time-for-given-digits/index.js - About 2 hrs to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Function spiralOrder has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
    Open

    export const spiralOrder = matrix => {
      let res = [];
      const row = matrix.length;
      if (!Array.isArray(matrix[0])) return matrix;
    
    
    Severity: Minor
    Found in src/54-spiral-matrix/index.js - About 2 hrs to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Function delNodes has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
    Open

    var delNodes = function (root, to_delete) {
      var res = [];
      var deleteSet = new Set(to_delete);
      dfs(null, root);
      if (!deleteSet.has(root.val)) res.push(root);
    Severity: Minor
    Found in src/1110-delete-nodes-and-return-forest/index.js - About 2 hrs to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Severity
    Category
    Status
    Source
    Language