leetcode contest 2Feb2025| Q2. Maximum Manhattan Distance After K Changes | python practice|medium

แชร์
ฝัง
  • เผยแพร่เมื่อ 8 ก.พ. 2025
  • leetcode contest 2Feb2025 | Q2. Maximum Manhattan Distance After K Changes | python practice | medium

ความคิดเห็น • 3

  • @adevopsbeginner
    @adevopsbeginner  7 วันที่ผ่านมา

    class Solution:
    def leetcode(self, s: str, k: int) -> int:
    nwse = [0,0,0,0]
    result = 0
    ll = len(s)
    for ii in range(ll):
    if s[ii] == "N":
    nwse[0] += 1
    elif s[ii] == "W":
    nwse[1] += 1
    elif s[ii] == "S":
    nwse[2] += 1
    elif s[ii] == "E":
    nwse[3] += 1
    minns = min(nwse[0],nwse[2])
    minew = min(nwse[1],nwse[3])
    maxns = max(nwse[0],nwse[2])
    maxew = max(nwse[1],nwse[3])
    manhattan = maxns-minns + maxew-minew + min(k,minns+minew)*2
    #print(ii,nwse,manhattan, result)
    result = max(result, manhattan)

    return result

  • @MultiUniverseExolore-s8m
    @MultiUniverseExolore-s8m 7 วันที่ผ่านมา +1

    code