Skip to main content

Command Palette

Search for a command to run...

Number of 1 Bits

Published
1 min read
Number of 1 Bits
G

As a Systems Engineer at Tata Consultancy Services, I deliver exceptional software products for mobile and web platforms, using agile methodologies and robust quality maintenance. I am experienced in performance testing, automation testing, API testing, and manual testing, with various tools and technologies such as Jmeter, Azure LoadTest, Selenium, Java, OOPS, Maven, TestNG, and Postman.

I have successfully developed and executed detailed test plans, test cases, and scripts for Android and web applications, ensuring high-quality standards and user satisfaction. I have also demonstrated my proficiency in manual REST API testing with Postman, as well as in end-to-end performance and automation testing using Jmeter and selenium with Java, TestNG and Maven. Additionally, I have utilized Azure DevOps for bug tracking and issue management.

Write a function that takes the binary representation of a positive integer and returns the number of set bits it has (also known as the Hamming weight).

LeetCode Problem - 191

class Solution {
    public int hammingWeight(int n) {
        // Convert the integer 'n' to its binary string representation
        String str = Integer.toBinaryString(n);

        // Initialize a counter to track the number of '1' bits
        int count = 0;

        // Loop through each character in the binary string
        for (char ch : str.toCharArray()) {
            // If the character is '1', increment the count
            if (ch == '1') count++;
        }

        // Return the total count of '1' bits
        return count;
    }
}

More from this blog

S

Software and Performance Testing Insights

462 posts

Results-Driven Agile QA Specialist | Expert in Mobile & Web Testing | Proficient in Test Planning, Execution, and Root Cause Analysis.