harrytothemoon / leetcodeAplus

Leetcode meeting note
2 stars 0 forks source link

[832] Flipping an Image #34

Open ShihTingJustin opened 3 years ago

ShihTingJustin commented 3 years ago

暴力暴力~

var flipAndInvertImage = function(A) {
    for (let i = 0; i < A.length; i++) {
      A[i] = A[i].reverse()
      for (let j = 0; j < A[i].length; j++) {
        A[i][j] === 1 ? A[i][j] = 0 : A[i][j] = 1
      }
    }
    return A
};

用 map 寫成一行

var flipAndInvertImage = function(A) {
  return A.map(a => a.reverse().map(itm => itm === 1 ? itm = 0 : itm = 1 ))
};
tsungtingdu commented 3 years ago
var flipAndInvertImage = function(A) {
    return A.map(i => i.reverse().map(i => i^1))
};
harrytothemoon commented 3 years ago
var flipAndInvertImage = function(A) {
    const horizon = A.map(x => x.reverse())
    const reverse = horizon.map(i => i.map(j => j = Number(!j)))
    return reverse
};
windate3411 commented 3 years ago

悠哉的分步驟寫

var flipAndInvertImage = function(A) {
  const reversedRows = A.map(row => row.reverse())
  const filppedImages = reversedRows.map(row => {
      return row.map(item => item === 0? 1: 0)
  })
  return filppedImages
};