Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to reverse the output Matrix of JZ19

2025-01-22 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly shows you "JZ19 how to reverse the output matrix", the content is easy to understand, clear, hope to help you solve your doubts, the following let the editor lead you to study and learn "how to reverse the output matrix of JZ19" this article.

The problem of JZ19 inverse output Matrix

Enter a matrix and print each number in clockwise order from outside to in. for example, if you enter the following 4 X 4 matrix: 12 3 4 5 6 6 7 8 9 10 11 12 13 14 15 16, then print out the numbers 1, 2, 4, 4, 4, 8, 4, 12, 16, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 9, 5, 6, 7, 11, 11, 10.

Train of thought

Locate the upper left and lower right coordinates of the current circle matrix

Code #-*-coding:utf-8-*-class Solution: # matrix type is a 2D list You need to return a list of def printMatrix (self, matrix): # Positioning left, upper and lower right point coordinates x1, y1, x2, y2 = 0,0, len (matrix [0]), len (matrix) res = [] while x2 > x1 and y2 > y1: for i in range (y1) X2): res.append (Matrix [x1] [I]) if y2-y1==1: break for i in range (x1x1, y2-1): res.append (Matrix [I] [x2-1]) for i in range (x2-1, y1-1) -1): res.append (Matrix [y2-1] [I]) if x2-x1==1: break for i in range (y2-2, x1,-1): res.append (Matrix [I] [y1]) x1, y1, x2, y2 = x1, y1, x2-1 Y2-1 return res if _ _ name__ = ='_ _ main__': matrix = [[1Power2 _ name__ = ='_ 4], [5 ~ 6 ~ 6 ~ 7 ~ 8], [13 ~ 14 ~ 14 ~ 15 ~ 16],] matrix2 = [1 ~ 2 ~ 2 ~ 3 ~ 4 ~ 4], [6 ~ 7 ~ 8 ~ 9 ~ 10], [11 ~ 12 ~ 13 ~ 14 ~ 15],] matrix3 = [1 ~ 2 ~ 3], [1 ~ 2] Matrix4 = [1], [2], [3], [4], [5] sl = Solution () print (sl.printMatrix2 (matrix4)), these are all the contents of the article "how to reverse JZ19 output Matrix" Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report