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

Support display sup/sub style for numbers #12

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
clearloop merged 1 commit into clearloop:master from hulufei:master
Mar 13, 2020

Conversation

Copy link
Contributor

@hulufei hulufei commented Mar 13, 2020

For example: leetcode problem 202

clearloop reacted with thumbs up emoji
@hulufei hulufei changed the title (削除) Support display sup/sub styles of numbers (削除ここまで) (追記) Support display sup/sub style for numbers (追記ここまで) Mar 13, 2020
Copy link
Owner

clearloop commented Mar 13, 2020
edited
Loading

Thanks!!!

 λ pcs cargo run p 202
 Finished dev [unoptimized + debuginfo] target(s) in 0.13s
 Running `target/debug/leetcode p 202`
[202] Happy Number is on the run...
Write an algorithm to determine if a number is "happy".
A happy number is a number defined by the following process: Starting with any positive integer, replace the number by the sum of the squares of its digits, and repeat the process until the number equals 1 (where it will stay), or it loops endlessly in a cycle which does not include 1. Those numbers for which this process ends in 1 are happy numbers.
--------------------------------------------------
Example: 
Input: 19
Output: true
Explanation: 
12 +たす 92 = 82
82 +たす 22 = 68
62 +たす 82 = 100
12 +たす 02 +たす 02 = 1

@clearloop clearloop merged commit 5ae6e61 into clearloop:master Mar 13, 2020
Comment on lines +112 to +138
pub fn superscript(n: u8) -> String {
if n == 0 {
"0".to_owned()
} else if n == 1 {
"1".to_owned()
} else if n == 2 {
"2".to_owned()
} else if n == 3 {
"3".to_owned()
} else if n == 4 {
"4".to_owned()
} else if n == 5 {
"5".to_owned()
} else if n == 6 {
"6".to_owned()
} else if n == 7 {
"7".to_owned()
} else if n == 8 {
"8".to_owned()
} else if n == 9 {
"9".to_owned()
} else if n >= 10 {
superscript(n / 10) + &superscript(n % 10)
} else {
n.to_string()
}
}
Copy link
Owner

@clearloop clearloop Mar 26, 2020
edited
Loading

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can write like:

pub fn superscript(n: u8) -> String {
 match n {
 0 => "0".to_string(),
 1 => "1".to_string(),
 2 => "2".to_string(),
 3 => "3".to_string(),
 4 => "4".to_string(),
 5 => "5".to_string(),
 6 => "6".to_string(),
 7 => "7".to_string(),
 8 => "8".to_string(),
 9 => "9".to_string(),
 x if x > 10 => (superscript(n / 10).parse().unwrap_or(0)
 + &superscript(n % 10).parse().unwrap_or(0))
 .to_string(),
 _ => n.to_string(),
 }
 }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Reviewers

@clearloop clearloop clearloop left review comments

Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

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