diff options
| author | Steve Lee <me@xiangyangli.com> | 2017-12-26 01:33:40 +0800 |
|---|---|---|
| committer | Steve Lee <me@xiangyangli.com> | 2017-12-26 01:33:40 +0800 |
| commit | 79a9c52fa923fc78074d88463449a8b7f95ca3ef (patch) | |
| tree | 80c2b596a7c41124845771dca99abd364e89d4c4 /Computer_Science/leetcode/48-rotate_image.c | |
| parent | 2e0e0f39d49296f0ffb99aea533a527174521d61 (diff) | |
| download | 42-79a9c52fa923fc78074d88463449a8b7f95ca3ef.tar.xz 42-79a9c52fa923fc78074d88463449a8b7f95ca3ef.zip | |
update leetcode solution
Diffstat (limited to 'Computer_Science/leetcode/48-rotate_image.c')
| -rw-r--r-- | Computer_Science/leetcode/48-rotate_image.c | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/Computer_Science/leetcode/48-rotate_image.c b/Computer_Science/leetcode/48-rotate_image.c new file mode 100644 index 0000000..785965f --- /dev/null +++ b/Computer_Science/leetcode/48-rotate_image.c @@ -0,0 +1,31 @@ +void helper(int** matrix, int start, int len) +{ + if(len <= 1) return; + + int tmp1, tmp2; + + for(int i = 0; i < len - 1; i++) { + //save top + //top to righ + tmp1 = matrix[start + i][start + len - 1]; + matrix[start + i][start + len - 1] = matrix[start][start + i]; + //right to button + tmp2 = matrix[start + len - 1][start + len - 1 - i]; + matrix[start + len - 1][start + len - 1 - i] = tmp1; + tmp1 = tmp2; + //buttom to left + tmp2 = matrix[start + len - 1 - i][start]; + matrix[start + len - 1 - i][start] = tmp1; + tmp1 = tmp2; + //left to top + matrix[start][start + i] = tmp1; + } + + helper(matrix, start + 1, len - 2); + +} +void rotate(int** matrix, int matrixRowSize, int matrixColSize) { + helper(matrix, 0, matrixRowSize); +} + + |
