Skip to content

Conversation

@ankitpatil7
Copy link
Owner

maxBits && sum + (1 << i) <= k) {
sum += 1 << i;
length++;
}
} else {
length++; < maxBits && sum + (1 << i) <= k) {
sum += 1 << i;
length++;
}
} else {
length++;cclass Solution {
public int longestSubsequence(String s, int k) {
int sum = 0;
int length = 0;
int maxBits = (int) (Math.log(k) / Math.log(2)) + 1;

    for (int i = 0; i < s.length(); i++) {
        char bit = s.charAt(s.length() - 1 - i);
        if (bit == '1') {
            if (i <

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants