document.write('
本题的思路为:从右上角开始对数组中的元素进行输出,实现代码如下:
 def rotateArr(arr):
 lens=len(arr)
 #打印二维数组右上半部分
 i=lens-1
 while i>0:
 row=0
 col=i
 while col<lens:
 print arr[row][col],
 row+=1
 col+=1
 print \'\\n\'
 i-=1
 #打印二维数组左下半部分(包括对角线)
 i=0
 while i<lens:
 row=i
 col=0
 while row<lens:
 print arr[row][col],
 row+=1
 col+=1
 print \'\\n\'
 i+=1
 
 if __name__="__main__":
 arr=[[1,2,3l,[4,5,6l,[7,8,9]]
 rotateArr(arr)
 程序的运行结果为:
 3
 2 6
 1 5 9
 4 8
 7
 算法性能分析:
 这种方法对数组中的每个元素都遍历了一次,因此,算法的时间复杂度为O(n2)。

 

');