{for(intj =0; j < N/2; ++j )// 次数确定:每次减两个,直到只剩下一个或者零个swap( matrix[i][j] , matrix[i][N-j-1] ); }// printPrintMatrix( matrix,"After rotate 90 degree\n"); }voidRotate90Degree(intmatrix[N][N] ){// printPrintMatrix( matrix,"Before");for(inti =0; ...
You are given annxn2D matrix representing an image. Rotate the image by 90 degrees (clockwise). Follow up: Could you do this in-place? 解题思路1:先将矩阵转置,然后将矩阵的每一行翻转,就可以得到所要求的矩阵了。为便于理解,制作了如下示意图. Figure 1: Illustration of transpose operation. Only ...
1.2 Remove Duplicates from Sorted Array II 1.3 Search in Rotated Sorted Array II 1.4 Median of Two Sorted Arrays 1.5 Longest Consecutive Sequence 1.6 Two Sum 1.7 Valid Sudoku 1.8 Trapping Rain Water 1.9 Swap Nodes in Pairs 1.10 Reverse Nodes in k-Group 2. 字符串 2.1 Valid Palindrome 2.2 Im...
class Solution { fun search(nums: IntArray, target: Int): Int { val rotateIndex = getRotateIndex(nums) val orderedNums = getOrderedNums(nums, rotateIndex) var left = 0 var right = orderedNums.size while (left < right) { val middle = (left + right) / 2 when { orderedNums[middle]...
396 Rotate Function 28.40% Easy 395 Longest Substring with At Least K Repeating Characters 32.50% Medium 394 Decode String 38.60% Medium 393 UTF-8 Validation 33.00% Medium 392 Is Subsequence 44.10% Medium 391 Perfect Rectangle 13.30% Hard 390 Elimination Game 12.50% Medium 389 Find the Difference...
0033 Search in Rotated Sorted Array Go 33.00% Medium 0034 Find First and Last Position of Element in Sorted Array Go 33.70% Medium 0035 Search Insert Position 40.90% Easy 0036 Valid Sudoku Go 43.50% Medium 0037 Sudoku Solver Go 37.40% Hard 0038 Count and Say 40.80% Easy 0039 Comb...
1.3 Search in Rotated Sorted Array II 1.4 Median of Two Sorted Arrays 1.5 Longest Consecutive Sequence 1.6 Two Sum 1.7 Valid Sudoku 1.8 Trapping Rain Water 1.9 Swap Nodes in Pairs 1.10 Reverse Nodes in k-Group 2. 字符串 2.1 Valid Palindrome 2.2 Implement strStr() 3.3 String to Integer (at...
这道题的核心是分析出rotate 90度等价于 先上下对折,然后对角线对折。 有了这个思路之后,难点在于如何对折对角线。这需要遍历主对角线右上方的元素即可,并将 (i,j) 和 (j,i) 位置的元素交换。代码如下: // 2. swap diagonalfor(inti=0;i<m;i++){for(intj=i;j<n;j++){// 注意这里是 j = iswa...
Rotate Image You are given an *n* x *n* 2D matrix representing an image. Rotate the image by 90 degrees (clockwise). Follow up:Could you do this in-place? **Most Pythonic - [::-1] and zip** The most pythonic solution is a simple one-liner using [::-1] to flip the matrix ...
Problem # You are given an n x n 2D matrix representing an image. # # Rotate the image by 90 degrees (clockwise). # # Note: # You have to rotate the image in-pl...