Ai
1 Star 2 Fork 5

LilithSangreal/LeetCode-Solutions

Create your Gitee Account
Explore and code with more than 13.5 million developers,Free private repositories !:)
Sign up
文件
Clone or Download
flower-planting-with-no-adjacent.py 469 Bytes
Copy Edit Raw Blame History
kamyu authored 2019-05-12 15:31 +08:00 . Create flower-planting-with-no-adjacent.py
# Time: O(n)
# Space: O(n)
class Solution(object):
def gardenNoAdj(self, N, paths):
"""
:type N: int
:type paths: List[List[int]]
:rtype: List[int]
"""
result = [0]*N
G = [[] for i in xrange(N)]
for x, y in paths:
G[x-1].append(y-1)
G[y-1].append(x-1)
for i in xrange(N):
result[i] = ({1, 2, 3, 4} - {result[j] for j in G[i]}).pop()
return result
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/LilithSangreal/LeetCode-Solutions.git
git@gitee.com:LilithSangreal/LeetCode-Solutions.git
LilithSangreal
LeetCode-Solutions
LeetCode-Solutions
master

Search