868. 二进制间距  显示英文描述 我的提交返回竞赛   用户通过次数201 用户尝试次数220 通过次数207 提交次数396 题目难度Easy 给定一个正整数 N,找到并返回 N 的二进制表示中两个连续的 1 之间的最长距离. 如果没有两个连续的 1,返回 0 . 示例 1: 输入:22 输出:2 解释: 22 的二进制是 0b10110 . 在 22 的二进制表示中,有三个 1,组成两对连续的 1 . 第一对连续的 1 中,两个 1 之间的距离为 2 . 第二对连续的 1 中,两个 1…
Given a positive integer N, find and return the longest distance between two consecutive 1's in the binary representation of N. If there aren't two consecutive 1's, return 0. Example 1: Input: 22 Output: 2 Explanation: 22 in binary is 0b10110. In the…
中文标题[二进制空白] 英文描述 A binary gap within a positive integer N is any maximal sequence of consecutive zeros that is surrounded by ones at both ends in the binary representation of N. For example, number 9 has binary representation 1001 and contains a bina…
Leetcode 67:Add Binary(二进制求和) (python.java) Given two binary strings, return their sum (also a binary string). The input strings are both non-empty and contains only characters 1 or 0. 给定两个二进制字符串,返回他们的和(用二进制表示). 输入为非空字符串且只包含数字 1 和 0. Example 1: Input…
problem 868. Binary Gap solution1: class Solution { public: int binaryGap(int N) { ; vector<int> pos; ; ) { ==) pos.push_back(k); k++; N >>=;//errr... } ; i<pos.size(); ++i) { res = max(res, pos[i]-pos[i-]); } return res; } }; solution2: cl…
868. 二进制间距 读懂题意就出来了 class Solution { public int binaryGap(int N) { String s = Integer.toBinaryString(N); int ans = 0; int k = -1; int i = 0; while (s.charAt(i) == '0') i++; for (; i < s.length(); i++) { if (s.charAt(i) == '1') { k++; ans = Math.max(a…
题目链接:Balanced Binary Tree | LeetCode OJ Given a binary tree, determine if it is height-balanced. For this problem, a height-balanced binary tree is defined as a binary tree in which the depth of the two subtrees of every node never differ by more tha…
题目链接:Validate Binary Search Tree | LeetCode OJ Given a binary tree, determine if it is a valid binary search tree (BST). Assume a BST is defined as follows: The left subtree of a node contains only nodes with keys less than the node's key. The right…
Serialization is the process of converting a data structure or object into a sequence of bits so that it can be stored in a file or memory buffer, or transmitted across a network connection link to be reconstructed later in the same or another comput…
LeetCode:Maximum Depth of Binary Tree [问题再现] Given a binary tree, find its maximum depth. The maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node. [优质算法] 算法一: public class Solution { public in…