回复: 2
跳转到指定楼层
上一主题 下一主题
收起左侧

snap 电面新题

全局:

2021(10-12月) 码农类General 硕士 全职@snapchat - 内推 - 技术电面  | 😃 Positive 😐 Average | Other | 在职跳槽

注册一亩三分地论坛,查看更多干货!

您需要 登录 才可以下载或查看附件。没有帐号?注册账号

x


# Implement a simplified game of minesweeper.   
# createBoard(mineLocations, width, height) - Creates a board. Returns board.
# printBoard(board) - Prints a board with an ad
您好!
本帖隐藏的内容需要积分高于 188 才可浏览
您当前积分为 0。
使用VIP即刻解锁阅读权限或查看其他获取积分的方式
游客,您好!
本帖隐藏的内容需要积分高于 188 才可浏览
您当前积分为 0。
VIP即刻解锁阅读权限 或 查看其他获取积分的方式
Unlock interview details and practice with AI
Curated Interview Questions from Top Companies
te revealed squares. e.g. "#" as hidden and "R" as revealed below.
# Should also add a new line after printing

评分

参与人数 2大米 +7 收起 理由
流天 + 1 赞一个
匿名用户-RQJJ5 + 6

查看全部评分


上一篇:狗vo+timeline
下一篇:系统设计 分布式锁
全局:
里扣无而酒

评分

参与人数 1大米 +1 收起 理由
goodluck_ccc + 1 给你点个赞!

查看全部评分

回复

使用道具 举报

全局:
  1. from typing import List

  2. # Represents a cell in the minesweeper board.
  3. # A cell has a value (either a number or a mine), and a state (either hidden or revealed).
  4. class Cell:
  5.     def __init__(self, value: str, state: str):
  6.         self.value = value
  7.         self.state = state

  8. # Creates a minesweeper board with the specified mine locations, width, and height.
  9. # The board is represented as a 2D list of Cell objects.
  10. def createBoard(mine_locations: List[Tuple[int, int]], width: int, height: int) -> List[List[Cell]]:
  11.     board = []
  12.     for i in range(height):
  13.         row = []
  14.         for j in range(width):
  15.             if (i, j) in mine_locations:
  16.                 cell = Cell('*', 'hidden')
  17.             else:
  18.                 cell = Cell(' ', 'hidden')
  19.             row.append(cell)
  20.         board.append(row)
  21.     return board

  22. # Prints the specified minesweeper board with an additional new line at the end.
  23. def printBoard(board: List[List[Cell]]):
  24.     for row in board:
  25.         for cell in row:
  26.             if cell.state == 'hidden':
  27.                 print('#', end='')
  28.             else:
  29.                 print(cell.value, end='')
  30.         print()
  31.     print()

  32. # Reveals the specified cell in the minesweeper board and prints the board.
  33. # If the cell contains a mine, prints "game over" and returns False.
  34. # Otherwise, returns True.
  35. def click(board: List[List[Cell]], x: int, y: int) -> bool:
  36.     if board[x][y].value == '*':
  37.         print('game over')
  38.         return False
  39.     board[x][y].state = 'revealed'
  40.     printBoard(board)
  41.     return True
复制代码
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册账号
隐私提醒:
  • ☑ 禁止发布广告,拉群,贴个人联系方式:找人请去🔗同学同事飞友,拉群请去🔗拉群结伴,广告请去🔗跳蚤市场,和 🔗租房广告|找室友
  • ☑ 论坛内容在发帖 30 分钟内可以编辑,过后则不能删帖。为防止被骚扰甚至人肉,不要公开留微信等联系方式,如有需求请以论坛私信方式发送。
  • ☑ 干货版块可免费使用 🔗超级匿名:面经(美国面经、中国面经、数科面经、PM面经),抖包袱(美国、中国)和录取汇报、定位选校版
  • ☑ 查阅全站 🔗各种匿名方法

本版积分规则

>
快速回复 返回顶部 返回列表