Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commita1113e2

Browse files
authored
Update 0343-integer-break.kt
1 parent40e7a58 commita1113e2

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

‎kotlin/0343-integer-break.kt

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,22 @@ class Solution {
5757
return res
5858
}
5959
}
60+
61+
// Mathimatically solved O(1)
62+
classSolution {
63+
funintegerBreak(n:Int):Int {
64+
if (n<4)return n-1
65+
66+
var res= n/3
67+
var rem= n%3
68+
69+
if (rem==1) {
70+
rem=4
71+
res--
72+
}elseif (rem==0) {
73+
rem=1
74+
}
75+
76+
return (Math.pow(3.toDouble(), res.toDouble())* rem).toInt()
77+
}
78+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp