File tree 4 files changed +68
-92
lines changed
0000-0099/0009.Palindrome Number
2800-2899/2862.Maximum Element-Sum of a Complete Subset of Indices
4 files changed +68
-92
lines changed Original file line number Diff line number Diff line change @@ -171,29 +171,6 @@ impl Solution {
171
171
}
172
172
```
173
173
174
- ``` js
175
- /**
176
- * @param {number} x
177
- * @return {boolean}
178
- */
179
- var isPalindrome = function (x ) {
180
- if (x < 0 || (x > 0 && x % 10 === 0 )) {
181
- return false ;
182
- }
183
- let y = 0 ;
184
- for (; y < x; x = ~~ (x / 10 )) {
185
- y = y * 10 + (x % 10 );
186
- }
187
- return x === y || x === ~~ (y / 10 );
188
- };
189
- ```
190
-
191
- <!-- tabs: end -->
192
-
193
- ### 方法二
194
-
195
- <!-- tabs: start -->
196
-
197
174
``` rust
198
175
impl Solution {
199
176
pub fn is_palindrome (mut x : i32 ) -> bool {
@@ -211,6 +188,23 @@ impl Solution {
211
188
}
212
189
```
213
190
191
+ ``` js
192
+ /**
193
+ * @param {number} x
194
+ * @return {boolean}
195
+ */
196
+ var isPalindrome = function (x ) {
197
+ if (x < 0 || (x > 0 && x % 10 === 0 )) {
198
+ return false ;
199
+ }
200
+ let y = 0 ;
201
+ for (; y < x; x = ~~ (x / 10 )) {
202
+ y = y * 10 + (x % 10 );
203
+ }
204
+ return x === y || x === ~~ (y / 10 );
205
+ };
206
+ ```
207
+
214
208
``` php
215
209
class Solution {
216
210
/**
Original file line number Diff line number Diff line change @@ -161,29 +161,6 @@ impl Solution {
161
161
}
162
162
```
163
163
164
- ``` js
165
- /**
166
- * @param {number} x
167
- * @return {boolean}
168
- */
169
- var isPalindrome = function (x ) {
170
- if (x < 0 || (x > 0 && x % 10 === 0 )) {
171
- return false ;
172
- }
173
- let y = 0 ;
174
- for (; y < x; x = ~~ (x / 10 )) {
175
- y = y * 10 + (x % 10 );
176
- }
177
- return x === y || x === ~~ (y / 10 );
178
- };
179
- ```
180
-
181
- <!-- tabs: end -->
182
-
183
- ### Solution 2
184
-
185
- <!-- tabs: start -->
186
-
187
164
``` rust
188
165
impl Solution {
189
166
pub fn is_palindrome (mut x : i32 ) -> bool {
@@ -201,6 +178,23 @@ impl Solution {
201
178
}
202
179
```
203
180
181
+ ``` js
182
+ /**
183
+ * @param {number} x
184
+ * @return {boolean}
185
+ */
186
+ var isPalindrome = function (x ) {
187
+ if (x < 0 || (x > 0 && x % 10 === 0 )) {
188
+ return false ;
189
+ }
190
+ let y = 0 ;
191
+ for (; y < x; x = ~~ (x / 10 )) {
192
+ y = y * 10 + (x % 10 );
193
+ }
194
+ return x === y || x === ~~ (y / 10 );
195
+ };
196
+ ```
197
+
204
198
``` php
205
199
class Solution {
206
200
/**
Original file line number Diff line number Diff line change @@ -81,6 +81,23 @@ class Solution:
81
81
return ans
82
82
```
83
83
84
+ ``` java
85
+ class Solution {
86
+ public long maximumSum (List<Integer > nums ) {
87
+ long ans = 0 ;
88
+ int n = nums. size();
89
+ for (int k = 1 ; k <= n; ++ k) {
90
+ long t = 0 ;
91
+ for (int j = 1 ; k * j * j <= n; ++ j) {
92
+ t += nums. get(k * j * j - 1 );
93
+ }
94
+ ans = Math . max(ans, t);
95
+ }
96
+ return ans;
97
+ }
98
+ }
99
+ ```
100
+
84
101
``` java
85
102
class Solution {
86
103
public long maximumSum (List<Integer > nums ) {
@@ -156,27 +173,4 @@ function maximumSum(nums: number[]): number {
156
173
157
174
<!-- tabs: end -->
158
175
159
- ### 方法二
160
-
161
- <!-- tabs: start -->
162
-
163
- ``` java
164
- class Solution {
165
- public long maximumSum (List<Integer > nums ) {
166
- long ans = 0 ;
167
- int n = nums. size();
168
- for (int k = 1 ; k <= n; ++ k) {
169
- long t = 0 ;
170
- for (int j = 1 ; k * j * j <= n; ++ j) {
171
- t += nums. get(k * j * j - 1 );
172
- }
173
- ans = Math . max(ans, t);
174
- }
175
- return ans;
176
- }
177
- }
178
- ```
179
-
180
- <!-- tabs: end -->
181
-
182
176
<!-- end -->
Original file line number Diff line number Diff line change @@ -103,6 +103,23 @@ class Solution {
103
103
}
104
104
```
105
105
106
+ ``` java
107
+ class Solution {
108
+ public long maximumSum (List<Integer > nums ) {
109
+ long ans = 0 ;
110
+ int n = nums. size();
111
+ for (int k = 1 ; k <= n; ++ k) {
112
+ long t = 0 ;
113
+ for (int j = 1 ; k * j * j <= n; ++ j) {
114
+ t += nums. get(k * j * j - 1 );
115
+ }
116
+ ans = Math . max(ans, t);
117
+ }
118
+ return ans;
119
+ }
120
+ }
121
+ ```
122
+
106
123
``` cpp
107
124
class Solution {
108
125
public:
@@ -152,27 +169,4 @@ function maximumSum(nums: number[]): number {
152
169
153
170
<!-- tabs: end -->
154
171
155
- ### Solution 2
156
-
157
- <!-- tabs: start -->
158
-
159
- ``` java
160
- class Solution {
161
- public long maximumSum (List<Integer > nums ) {
162
- long ans = 0 ;
163
- int n = nums. size();
164
- for (int k = 1 ; k <= n; ++ k) {
165
- long t = 0 ;
166
- for (int j = 1 ; k * j * j <= n; ++ j) {
167
- t += nums. get(k * j * j - 1 );
168
- }
169
- ans = Math . max(ans, t);
170
- }
171
- return ans;
172
- }
173
- }
174
- ```
175
-
176
- <!-- tabs: end -->
177
-
178
172
<!-- end -->
You can’t perform that action at this time.
0 commit comments