Skip to content

feat:add typescript, cpp and rust solutions for (leetcode 1431,lcof 64) #261

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions lcof/面试题64. 求1+2+…+n/Solution.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class Solution
{
public:
int sumNums(int n)
{
n && (n += sumNums(n - 1));
return n;
}
};
6 changes: 6 additions & 0 deletions lcof/面试题64. 求1+2+…+n/Solution.rs
Original file line number Diff line number Diff line change
@@ -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
}
}
3 changes: 3 additions & 0 deletions lcof/面试题64. 求1+2+…+n/Solution.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
var sumNums = function (n: number): number {
return n && n + sumNums(n - 1);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
class Solution
{
public:
vector<bool> kidsWithCandies(vector<int> &candies, int extraCandies)
{
int maxCandies = *max_element(candies.begin(), candies.end());
vector<bool> ans;
for (int candy : candies)
{
ans.push_back(candy + extraCandies >= maxCandies);
}
return ans;
}
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
impl Solution {
pub fn kids_with_candies(candies: Vec<i32>, extra_candies: i32) -> Vec<bool> {
let max_candies=*candies.iter().max().unwrap();
return candies.iter().map(|x| x+extra_candies>=max_candies).collect();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
var kidsWithCandies = function (candies: number[], extraCandies: number): boolean[] {
let maxCandies = Math.max(...candies);
return candies.map(candy => candy + extraCandies >= maxCandies);
};