Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 0a8700c

Browse files
authored
Merge pull request doocs#3 from doocs/master
merge pull
2 parents 6990456 + e664016 commit 0a8700c

File tree

8 files changed

+71
-0
lines changed

8 files changed

+71
-0
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
class Solution
2+
{
3+
public:
4+
int sumNums(int n)
5+
{
6+
n && (n += sumNums(n - 1));
7+
return n;
8+
}
9+
};
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
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+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
var sumNums = function (n: number): number {
2+
return n && n + sumNums(n - 1);
3+
};
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/**
2+
* Definition for a binary tree node.
3+
* class TreeNode {
4+
* val: number
5+
* left: TreeNode | null
6+
* right: TreeNode | null
7+
* constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {
8+
* this.val = (val===undefined ? 0 : val)
9+
* this.left = (left===undefined ? null : left)
10+
* this.right = (right===undefined ? null : right)
11+
* }
12+
* }
13+
*/
14+
type TreeNodeOptional = TreeNode | null;
15+
const isSame = (a: TreeNodeOptional, b: TreeNodeOptional): boolean => {
16+
if (!a && !b) return true;
17+
if (!a || !b) return false;
18+
return a.val === b.val && isSame(a.left, b.right) && isSame(a.right, b.left);
19+
};
20+
var isSymmetric = function (root: TreeNode | null): boolean {
21+
if (!root) return true;
22+
return isSame(root.left, root.right);
23+
};
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
declare class TreeNode {
2+
val: number;
3+
left: TreeNode | null;
4+
right: TreeNode | null;
5+
constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null);
6+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
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+
};
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
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+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
var kidsWithCandies = function (candies: number[], extraCandies: number): boolean[] {
2+
let maxCandies = Math.max(...candies);
3+
return candies.map(candy => candy + extraCandies >= maxCandies);
4+
};

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /