File tree 3 files changed +49
-0
lines changed
solution/1900-1999/1903.Largest Odd Number in String
3 files changed +49
-0
lines changed Original file line number Diff line number Diff line change @@ -85,6 +85,24 @@ class Solution {
85
85
}
86
86
```
87
87
88
+ ### ** JavaScript**
89
+
90
+ ``` js
91
+ /**
92
+ * @param {string} num
93
+ * @return {string}
94
+ */
95
+ var largestOddNumber = function (num ) {
96
+ let n = num .length ;
97
+ for (let j = n - 1 ; j >= 0 ; j-- ) {
98
+ if (num .charAt (j) & 1 == 1 ) {
99
+ return num .slice (0 , j+ 1 );
100
+ }
101
+ }
102
+ return ' ' ;
103
+ };
104
+ ```
105
+
88
106
### ** C++**
89
107
90
108
``` cpp
Original file line number Diff line number Diff line change @@ -73,6 +73,24 @@ class Solution {
73
73
}
74
74
```
75
75
76
+ ### ** JavaScript**
77
+
78
+ ``` js
79
+ /**
80
+ * @param {string} num
81
+ * @return {string}
82
+ */
83
+ var largestOddNumber = function (num ) {
84
+ let n = num .length ;
85
+ for (let j = n - 1 ; j >= 0 ; j-- ) {
86
+ if (num .charAt (j) & 1 == 1 ) {
87
+ return num .slice (0 , j+ 1 );
88
+ }
89
+ }
90
+ return ' ' ;
91
+ };
92
+ ```
93
+
76
94
### ** C++**
77
95
78
96
``` cpp
Original file line number Diff line number Diff line change
1
+ /**
2
+ * @param {string } num
3
+ * @return {string }
4
+ */
5
+ var largestOddNumber = function ( num ) {
6
+ let n = num . length ;
7
+ for ( let j = n - 1 ; j >= 0 ; j -- ) {
8
+ if ( num . charAt ( j ) & 1 == 1 ) {
9
+ return num . slice ( 0 , j + 1 ) ;
10
+ }
11
+ }
12
+ return '' ;
13
+ } ;
You can’t perform that action at this time.
0 commit comments