Skip to main content

Command Palette

Search for a command to run...

Power of Three

Published
1 min read
Power of Three
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.

Given an integer n, return true if it is a power of three. Otherwise, return false.

An integer n is a power of three, if there exists an integer x such that n == 3<sup>x</sup>.

LeetCode Problem - 326

class Solution {
    // This method checks if a given integer 'n' is a power of three.
    public boolean isPowerOfThree(int n) {
        // Iterate through a loop while 'n' is greater than 0.
        while(n > 0){
            // If 'n' is equal to 1, it means 'n' is a power of three, so return true.
            if(n == 1) 
                return true;
            // If 'n' is not divisible by 3 (i.e., 'n' is not a multiple of 3), break the loop.
            if(n % 3 != 0) 
                break;
            // Divide 'n' by 3 to check the next power of three.
            n /= 3;
        }
        // If the loop finishes and 'n' is not equal to 1, it means 'n' is not a power of three, so return false.
        return false;
    }
}

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.