Shohei Yoshida
Shohei Yoshida's Blog

Shohei Yoshida's Blog

LeetCode 48. Rotate Image in F#

Shohei Yoshida's photo
Shohei Yoshida
·Aug 30, 2022·

1 min read

URL

leetcode.com/problems/rotate-image

Code

github.com/syohex/dotnet-study/blob/master/..

let rotate (matrix: int [,]) : unit =
    let n = Array2D.length1 matrix

    for i in 0 .. (n / 2 - 1) do
        for j in 0 .. (n - 1) do
            let tmp = matrix.[i, j]
            matrix.[i, j] <- matrix.[n - 1 - i, j]
            matrix.[n - 1 - i, j] <- tmp

    for i in 0 .. (n - 1) do
        for j in (i + 1) .. (n - 1) do
            let tmp = matrix.[i, j]
            matrix.[i, j] <- matrix.[j, i]
            matrix.[j, i] <- tmp

    ()
 
Share this