File tree Expand file tree Collapse file tree 3 files changed +39
-0
lines changed
lcci/08.05.Recursive Mulitply Expand file tree Collapse file tree 3 files changed +39
-0
lines changed Original file line number Diff line number Diff line change @@ -110,6 +110,20 @@ impl Solution {
110
110
}
111
111
```
112
112
113
+ ``` swift
114
+ class Solution {
115
+ func multiply (_ A : Int , _ B : Int ) -> Int {
116
+ if B == 1 {
117
+ return A
118
+ }
119
+ if (B & 1 ) == 1 {
120
+ return (multiply (A, B >> 1 ) << 1 ) + A
121
+ }
122
+ return multiply (A, B >> 1 ) << 1
123
+ }
124
+ }
125
+ ```
126
+
113
127
<!-- tabs: end -->
114
128
115
129
<!-- end -->
Original file line number Diff line number Diff line change @@ -115,6 +115,20 @@ impl Solution {
115
115
}
116
116
```
117
117
118
+ ``` swift
119
+ class Solution {
120
+ func multiply (_ A : Int , _ B : Int ) -> Int {
121
+ if B == 1 {
122
+ return A
123
+ }
124
+ if (B & 1 ) == 1 {
125
+ return (multiply (A, B >> 1 ) << 1 ) + A
126
+ }
127
+ return multiply (A, B >> 1 ) << 1
128
+ }
129
+ }
130
+ ```
131
+
118
132
<!-- tabs: end -->
119
133
120
134
<!-- end -->
Original file line number Diff line number Diff line change
1
+ class Solution {
2
+ func multiply( _ A: Int , _ B: Int ) -> Int {
3
+ if B == 1 {
4
+ return A
5
+ }
6
+ if ( B & 1 ) == 1 {
7
+ return ( multiply ( A, B >> 1 ) << 1 ) + A
8
+ }
9
+ return multiply ( A, B >> 1 ) << 1
10
+ }
11
+ }
You can’t perform that action at this time.
0 commit comments