题解 | #棋子翻转#
棋子翻转
https://www.nowcoder.com/practice/a8c89dc768c84ec29cbf9ca065e3f6b4?tpId=182&tqId=34397&rp=1&ru=/exam/oj&qru=/exam/oj&sourceUrl=%2Fexam%2Foj%3Fpage%3D1%26tab%3D%25E5%2590%258D%25E4%25BC%2581%25E7%259C%259F%25E9%25A2%2598%26topicId%3D182&difficulty=undefined&judgeStatus=undefined&tags=&title=
/** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param A int整型二维数组 * @param f int整型二维数组 * @return int整型二维数组 */ function flipChess( A , f ) { // write code here len = f.length; for(let i=0;i<len;i++){ //shang if(f[i][0]-2 >=0){ //console.log(A[f[i][0]-2][f[i][1]-1]); A[f[i][0]-2][f[i][1]-1]=revear(A[f[i][0]-2][f[i][1]-1]); } //zuo if(f[i][1]-2 >=0){ A[f[i][0]-1][f[i][1]-2]=revear(A[f[i][0]-1][f[i][1]-2]); } //you if(f[i][1]<4){ A[f[i][0]-1][f[i][1]]=revear(A[f[i][0]-1][f[i][1]]); } //xia if(f[i][0]<4){ A[f[i][0]][f[i][1]-1]=revear(A[f[i][0]][f[i][1]-1]); } } return A; function revear(n){ if(n==1){ return 0; }else{ return 1; } } } module.exports = { flipChess : flipChess };