1017. Convert to Base -2 Medium
1/**
2 * [1017] Convert to Base -2
3 *
4 * Given an integer n, return a binary string representing its representation in base -2.
5 * Note that the returned string should not have leading zeros unless the string is "0".
6 *
7 * Example 1:
8 *
9 * Input: n = 2
10 * Output: "110"
11 * Explantion: (-2)^2 + (-2)^1 = 2
12 *
13 * Example 2:
14 *
15 * Input: n = 3
16 * Output: "111"
17 * Explantion: (-2)^2 + (-2)^1 + (-2)^0 = 3
18 *
19 * Example 3:
20 *
21 * Input: n = 4
22 * Output: "100"
23 * Explantion: (-2)^2 = 4
24 *
25 *
26 * Constraints:
27 *
28 * 0 <= n <= 10^9
29 *
30 */
31pub struct Solution {}
32
33// problem: https://leetcode.com/problems/convert-to-base-2/
34// discuss: https://leetcode.com/problems/convert-to-base-2/discuss/?currentPage=1&orderBy=most_votes&query=
35
36// submission codes start here
37
38impl Solution {
39 pub fn base_neg2(n: i32) -> String {
40 String::new()
41 }
42}
43
44// submission codes end
45
46#[cfg(test)]
47mod tests {
48 use super::*;
49
50 #[test]
51 fn test_1017() {
52 }
53}
54
Back
© 2025 bowen.ge All Rights Reserved.