LeetCode-59-Spiral Matrix II 模拟水题
来源:互联网 发布:中银淘宝信用卡查询 编辑:程序博客网 时间:2024/05/19 03:25
class Solution(object): def generateMatrix(self, n): """ :type n: int :rtype: List[List[int]] """ if n==0:return [] d=[[0,1],[1,0],[0,-1],[-1,0]] ans=[[0 for x in range(n)]for y in range(n)] x=0 y=0 direction=0 num=1 ans[0][0]=num for i in range(1,n*n): while(True): newx=x+d[direction][0] newy=y+d[direction][1] if newx>=0 and newx<n and newy>=0 and newy<n and ans[newx][newy]==0: num+=1 ans[newx][newy]=num x=newx y=newy break else: direction=(direction+1)%4 return ans
阅读全文
1 0
- LeetCode-59-Spiral Matrix II 模拟水题
- LeetCode 59: Spiral Matrix II
- [leetcode 59] Spiral Matrix II
- [LeetCode 59] Spiral Matrix II
- leetcode || 59、 Spiral Matrix II
- Spiral Matrix II - LeetCode 59
- Leetcode #59 Spiral Matrix II
- leetcode 59: Spiral Matrix II
- Leetcode#59||Spiral Matrix II
- leetcode 59:Spiral Matrix II
- 【LEETCODE】59-Spiral Matrix II
- 【leetcode】【59】Spiral Matrix II
- LeetCode 59 - Spiral Matrix II
- LeetCode 59 Spiral Matrix II
- 【LeetCode-59】Spiral Matrix II
- LeetCode 59 Spiral Matrix II
- Leetcode 59 Spiral Matrix II
- leetcode-59 Spiral Matrix II
- java全排列
- Netty介绍(附视频教程)
- 2.php访问mysql数据库(Create Retrieve Update Delete:增删改查)
- 从微服务开始(三):基本模式与最佳实践
- 剑指offer之五---旋转数组的最小数字
- LeetCode-59-Spiral Matrix II 模拟水题
- 读取GRE AWA Sim的paw文件
- Java基础类型与包装类
- android多线程-AsyncTask之工作原理深入解析(上)
- LeetCode 122. Best Time to Buy and Sell Stock II (Easy)
- C语言复习-01
- 19. Remove Nth Node From End of List
- 头插法创建单链表代码实现
- 字符串