diff --git a/solution/1200-1299/1227.Airplane Seat Assignment Probability/README.md b/solution/1200-1299/1227.Airplane Seat Assignment Probability/README.md index f8c45e54f728d..d41015c50d85e 100644 --- a/solution/1200-1299/1227.Airplane Seat Assignment Probability/README.md +++ b/solution/1200-1299/1227.Airplane Seat Assignment Probability/README.md @@ -142,6 +142,8 @@ f(n) = \begin{cases} \end{cases} $$ +时间复杂度 $O(1)$,空间复杂度 $O(1)$。 + #### Python3 @@ -184,6 +186,24 @@ func nthPersonGetsNthSeat(n int) float64 { } ``` +#### TypeScript + +```ts +function nthPersonGetsNthSeat(n: number): number { + return n === 1 ? 1 : 0.5; +} +``` + +#### Rust + +```rust +impl Solution { + pub fn nth_person_gets_nth_seat(n: i32) -> f64 { + return if n == 1 { 1.0 } else { 0.5 }; + } +} +``` + diff --git a/solution/1200-1299/1227.Airplane Seat Assignment Probability/README_EN.md b/solution/1200-1299/1227.Airplane Seat Assignment Probability/README_EN.md index 599e4ab4240b3..e28bf00f3d04f 100644 --- a/solution/1200-1299/1227.Airplane Seat Assignment Probability/README_EN.md +++ b/solution/1200-1299/1227.Airplane Seat Assignment Probability/README_EN.md @@ -136,6 +136,8 @@ f(n) = \begin{cases} \end{cases} $$ +The time complexity of this solution is $O(1)$, and the space complexity is $O(1)$. + #### Python3 @@ -178,6 +180,24 @@ func nthPersonGetsNthSeat(n int) float64 { } ``` +#### TypeScript + +```ts +function nthPersonGetsNthSeat(n: number): number { + return n === 1 ? 1 : 0.5; +} +``` + +#### Rust + +```rust +impl Solution { + pub fn nth_person_gets_nth_seat(n: i32) -> f64 { + return if n == 1 { 1.0 } else { 0.5 }; + } +} +``` + diff --git a/solution/1200-1299/1227.Airplane Seat Assignment Probability/Solution.rs b/solution/1200-1299/1227.Airplane Seat Assignment Probability/Solution.rs new file mode 100644 index 0000000000000..9fadbaecb57a2 --- /dev/null +++ b/solution/1200-1299/1227.Airplane Seat Assignment Probability/Solution.rs @@ -0,0 +1,5 @@ +impl Solution { + pub fn nth_person_gets_nth_seat(n: i32) -> f64 { + return if n == 1 { 1.0 } else { 0.5 }; + } +} diff --git a/solution/1200-1299/1227.Airplane Seat Assignment Probability/Solution.ts b/solution/1200-1299/1227.Airplane Seat Assignment Probability/Solution.ts new file mode 100644 index 0000000000000..fa43a6faf0aec --- /dev/null +++ b/solution/1200-1299/1227.Airplane Seat Assignment Probability/Solution.ts @@ -0,0 +1,3 @@ +function nthPersonGetsNthSeat(n: number): number { + return n === 1 ? 1 : 0.5; +}