提交 bc946b48 编写于 作者: 梦境迷离's avatar 梦境迷离

rust leetcode

上级 51579e83
...@@ -796,5 +796,21 @@ impl Solution { ...@@ -796,5 +796,21 @@ impl Solution {
} }
true true
} }
//位运算
pub fn is_unique2(astr: String) -> bool {
let cs = astr.chars();
let mut mark = 0;
let mut mark_bit = 0;
for c in cs {
mark_bit = c as i32 - ('a' as i32);
if (mark & (1 << mark_bit)) != 0 {
return false;
} else {
mark |= 1 << mark_bit
}
}
true
}
} }
``` ```
\ No newline at end of file
...@@ -1088,10 +1088,27 @@ fn interview_01_01() { ...@@ -1088,10 +1088,27 @@ fn interview_01_01() {
} }
true true
} }
//位运算
pub fn is_unique2(astr: String) -> bool {
let cs = astr.chars();
let mut mark = 0;
let mut mark_bit = 0;
for c in cs {
mark_bit = c as i32 - ('a' as i32);
if (mark & (1 << mark_bit)) != 0 {
return false;
} else {
mark |= 1 << mark_bit
}
}
true
}
} }
let ret = Solution::is_unique("abc".to_owned()); let ret = Solution::is_unique("abc".to_owned());
println!("{}", ret) let ret2 = Solution::is_unique2("abc".to_owned());
println!("{}", ret);
println!("{}", ret2)
} }
///所有方法调用 ///所有方法调用
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册