外網(wǎng)視頻網(wǎng)站做泥聲控百度seo權(quán)重
目錄
小前言
思路:
上代碼
lucky ending?
小前言
經(jīng)過漫長的停更周期-----1個(gè)月
我決定鐵血回歸!!!
思路:
兩層for循環(huán)暴力最快了這種小小范圍題,主要是第一行和第一列的邊界處理,我分為左上角,第一行,第一列,一般情況來處理。對(duì)于一般情況的總體判斷思路,采取當(dāng)前為X時(shí),左邊和上邊都為 . 那么num+1
上代碼
class Solution(object):def countBattleships(self, board):""":type board: List[List[str]]:rtype: int"""m=len(board)n=len(board[0])num=0for i in range(m):for j in range(n):if i==0 and j==0 and board[i][j]=="X":num+=1continueif i==0 and board[i][j]=="X" and board[i][j-1]==".":num+=1continueif j==0 and board[i][j]=="X" and board[i-1][j]==".":num+=1continueif board[i][j]=="X" and board[i-1][j]=="." and board[i][j-1]==".":num+=1return num
lucky ending?
?