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 e56d1eb

Browse files
committed
Solve #258
1 parent 665620a commit e56d1eb

File tree

3 files changed

+77
-0
lines changed

3 files changed

+77
-0
lines changed

‎src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,3 +206,5 @@ mod n0239_sliding_window_maximum;
206206
mod n0241_different_ways_to_add_parentheses;
207207
mod n0242_valid_anagram;
208208
mod n0257_binary_tree_paths;
209+
mod n0258_add_digits;
210+
mod n0260_single_number_iii;

‎src/n0258_add_digits.rs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/**
2+
* [258] Add Digits
3+
*
4+
* Given a non-negative integer num, repeatedly add all its digits until the result has only one digit.
5+
*
6+
* Example:
7+
*
8+
*
9+
* Input: 38
10+
* Output: 2
11+
* Explanation: The process is like: 3 + 8 = 11, 1 + 1 = 2.
12+
* Since 2 has only one digit, return it.
13+
*
14+
*
15+
* Follow up:<br />
16+
* Could you do it without any loop/recursion in O(1) runtime?
17+
*/
18+
pub struct Solution {}
19+
20+
// submission codes start here
21+
22+
impl Solution {
23+
pub fn add_digits(num: i32) -> i32 {
24+
1 + ((num - 1) % 9)
25+
}
26+
}
27+
28+
// submission codes end
29+
30+
#[cfg(test)]
31+
mod tests {
32+
use super::*;
33+
34+
#[test]
35+
fn test_258() {
36+
assert_eq!(Solution::add_digits(1234), 1);
37+
}
38+
}

‎src/n0260_single_number_iii.rs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/**
2+
* [260] Single Number III
3+
*
4+
* Given an array of numbers nums, in which exactly two elements appear only once and all the other elements appear exactly twice. Find the two elements that appear only once.
5+
*
6+
* Example:
7+
*
8+
*
9+
* Input: [1,2,1,3,2,5]
10+
* Output: [3,5]
11+
*
12+
* Note:
13+
*
14+
* <ol>
15+
* The order of the result is not important. So in the above example, [5, 3] is also correct.
16+
* Your algorithm should run in linear runtime complexity. Could you implement it using only constant space complexity?
17+
* </ol>
18+
*/
19+
pub struct Solution {}
20+
21+
// submission codes start here
22+
23+
impl Solution {
24+
pub fn single_number(nums: Vec<i32>) -> Vec<i32> {
25+
vec![]
26+
}
27+
}
28+
29+
// submission codes end
30+
31+
#[cfg(test)]
32+
mod tests {
33+
use super::*;
34+
35+
#[test]
36+
fn test_260() {}
37+
}

0 commit comments

Comments
(0)

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