diff --git "a/lcof/\351\235\242\350\257\225\351\242\23064. \346\261\2021+2+\342\200\246+n/Solution.cpp" "b/lcof/\351\235\242\350\257\225\351\242\23064. \346\261\2021+2+\342\200\246+n/Solution.cpp" new file mode 100644 index 0000000000000..215cec658a829 --- /dev/null +++ "b/lcof/\351\235\242\350\257\225\351\242\23064. \346\261\2021+2+\342\200\246+n/Solution.cpp" @@ -0,0 +1,9 @@ +class Solution +{ +public: + int sumNums(int n) + { + n && (n += sumNums(n - 1)); + return n; + } +}; \ No newline at end of file diff --git "a/lcof/\351\235\242\350\257\225\351\242\23064. \346\261\2021+2+\342\200\246+n/Solution.rs" "b/lcof/\351\235\242\350\257\225\351\242\23064. \346\261\2021+2+\342\200\246+n/Solution.rs" new file mode 100644 index 0000000000000..f31d3c15f5ddb --- /dev/null +++ "b/lcof/\351\235\242\350\257\225\351\242\23064. \346\261\2021+2+\342\200\246+n/Solution.rs" @@ -0,0 +1,6 @@ +impl Solution { + pub fn sum_nums(mut n: i32) -> i32 { + n!=0&&(n+=Solution::sum_nums(n-1),true).1; + n + } +} \ No newline at end of file diff --git "a/lcof/\351\235\242\350\257\225\351\242\23064. \346\261\2021+2+\342\200\246+n/Solution.ts" "b/lcof/\351\235\242\350\257\225\351\242\23064. \346\261\2021+2+\342\200\246+n/Solution.ts" new file mode 100644 index 0000000000000..1cafe4827b4ea --- /dev/null +++ "b/lcof/\351\235\242\350\257\225\351\242\23064. \346\261\2021+2+\342\200\246+n/Solution.ts" @@ -0,0 +1,3 @@ +var sumNums = function (n: number): number { + return n && n + sumNums(n - 1); +}; diff --git a/solution/1400-1499/1431.Kids With the Greatest Number of Candies/Solution.cpp b/solution/1400-1499/1431.Kids With the Greatest Number of Candies/Solution.cpp new file mode 100644 index 0000000000000..d627433672ed6 --- /dev/null +++ b/solution/1400-1499/1431.Kids With the Greatest Number of Candies/Solution.cpp @@ -0,0 +1,14 @@ +class Solution +{ +public: + vector kidsWithCandies(vector &candies, int extraCandies) + { + int maxCandies = *max_element(candies.begin(), candies.end()); + vector ans; + for (int candy : candies) + { + ans.push_back(candy + extraCandies >= maxCandies); + } + return ans; + } +}; \ No newline at end of file diff --git a/solution/1400-1499/1431.Kids With the Greatest Number of Candies/Solution.rs b/solution/1400-1499/1431.Kids With the Greatest Number of Candies/Solution.rs new file mode 100644 index 0000000000000..908de4e985a91 --- /dev/null +++ b/solution/1400-1499/1431.Kids With the Greatest Number of Candies/Solution.rs @@ -0,0 +1,6 @@ +impl Solution { + pub fn kids_with_candies(candies: Vec, extra_candies: i32) -> Vec { + let max_candies=*candies.iter().max().unwrap(); + return candies.iter().map(|x| x+extra_candies>=max_candies).collect(); + } +} \ No newline at end of file diff --git a/solution/1400-1499/1431.Kids With the Greatest Number of Candies/Solution.ts b/solution/1400-1499/1431.Kids With the Greatest Number of Candies/Solution.ts new file mode 100644 index 0000000000000..3f9eee1779c60 --- /dev/null +++ b/solution/1400-1499/1431.Kids With the Greatest Number of Candies/Solution.ts @@ -0,0 +1,4 @@ +var kidsWithCandies = function (candies: number[], extraCandies: number): boolean[] { + let maxCandies = Math.max(...candies); + return candies.map(candy => candy + extraCandies >= maxCandies); +}; \ No newline at end of file