File tree 6 files changed +42
-0
lines changed
solution/1400-1499/1431.Kids With the Greatest Number of Candies
6 files changed +42
-0
lines changed Original file line number Diff line number Diff line change
1
+ class Solution
2
+ {
3
+ public:
4
+ int sumNums (int n)
5
+ {
6
+ n && (n += sumNums (n - 1 ));
7
+ return n;
8
+ }
9
+ };
Original file line number Diff line number Diff line change
1
+ impl Solution {
2
+ pub fn sum_nums ( mut n : i32 ) -> i32 {
3
+ n!=0 &&( n+=Solution :: sum_nums ( n-1 ) , true ) . 1 ;
4
+ n
5
+ }
6
+ }
Original file line number Diff line number Diff line change
1
+ var sumNums = function ( n : number ) : number {
2
+ return n && n + sumNums ( n - 1 ) ;
3
+ } ;
Original file line number Diff line number Diff line change
1
+ class Solution
2
+ {
3
+ public:
4
+ vector<bool > kidsWithCandies (vector<int > &candies, int extraCandies)
5
+ {
6
+ int maxCandies = *max_element (candies.begin (), candies.end ());
7
+ vector<bool > ans;
8
+ for (int candy : candies)
9
+ {
10
+ ans.push_back (candy + extraCandies >= maxCandies);
11
+ }
12
+ return ans;
13
+ }
14
+ };
Original file line number Diff line number Diff line change
1
+ impl Solution {
2
+ pub fn kids_with_candies ( candies : Vec < i32 > , extra_candies : i32 ) -> Vec < bool > {
3
+ let max_candies=* candies. iter ( ) . max ( ) . unwrap ( ) ;
4
+ return candies. iter ( ) . map ( |x| x+extra_candies>=max_candies) . collect ( ) ;
5
+ }
6
+ }
Original file line number Diff line number Diff line change
1
+ var kidsWithCandies = function ( candies : number [ ] , extraCandies : number ) : boolean [ ] {
2
+ let maxCandies = Math . max ( ...candies ) ;
3
+ return candies . map ( candy => candy + extraCandies >= maxCandies ) ;
4
+ } ;
You can’t perform that action at this time.
0 commit comments