diff --git a/Java/Happy-Number.java b/Java/Happy-Number.java new file mode 100644 index 00000000..81093136 --- /dev/null +++ b/Java/Happy-Number.java @@ -0,0 +1,31 @@ +class HappyNumber { + public boolean isHappy(int n) { + int num1, num2; + + num1 = num2 = n; + do + { + num1 = SquareSum(num1); + + + num2 = SquareSum(SquareSum(num2)); + + } + while (num1 != num2); + + return (num1 == 1); +} + + +static int SquareSum(int n) + { + int square = 0; + while (n!= 0) + { + square += (n % 10) * (n % 10); + n /= 10; + } + return square; + } + +} \ No newline at end of file diff --git a/Java/Power-of-Three.java b/Java/Power-of-Three.java new file mode 100644 index 00000000..74fdfe41 --- /dev/null +++ b/Java/Power-of-Three.java @@ -0,0 +1,15 @@ +class Solution { + public boolean isPowerOfThree(int n) { + + if(n < 1) + { + return false; + } + + while(n % 3 == 0) + { + n = n/3; + } + return n==1; + } +} \ No newline at end of file diff --git a/README.md b/README.md index d7409911..572a239c 100644 --- a/README.md +++ b/README.md @@ -226,7 +226,8 @@ Check out ---> [Sample PR](https://github.com/codedecks-in/LeetCode-Solutions/pu | 204 | [Count Primes](https://leetcode.com/problems/count-primes) | [C++](./C++/Count-Primes.cpp) | _O(n(log(logn)))_ | _O(n)_ | Easy | Math | | | 168 | [Excel Sheet Column Title](https://leetcode.com/problems/excel-sheet-column-title) | [C++](./C++/Excel-Sheet-Column-Title.cpp) | _O(n)_ | _O(n)_ | Easy | String | | | 007 | [Reverse Integer](https://leetcode.com/problems/reverse-integer) | [Java](./Java/reverse-integer.java)
[C++](./C++/Reverse-Integer.cpp) | _O(n)_ | _O(n)_ | Easy | Math | | - +| 202 | [Happy Number](https://leetcode.com/problems/happy-number) | [Java](./Java/Happy-Number.java) | _O(n^2)_ | _O(n)_ | Easy | Math | | +| 326 | [Power of Three](https://leetcode.com/problems/power-of-three) | [Java](./Java/Power-of-Three.java) | _O(logn)_ | _O(n)_ | Easy | Math | |
⬆️ Back to Top @@ -357,10 +358,12 @@ DISCLAIMER: This above mentioned resources have affiliate links, which means if | [Girish Thatte](https://github.com/girishgr8/)
| India | Java | [Leetcode](https://leetcode.com/girish13/)
[Hackerrank](https://www.hackerrank.com/procoder_13)
[Codechef](https://www.codechef.com/procoder_13) | | [Kevin Chittilapilly](https://github.com/KevinChittilapilly)
| India | Java | [Leetcode](https://leetcode.com/being_kevin/)
[Hackerrank](https://www.hackerrank.com/ckevinvarghese11)
[Kaggle](https://www.kaggle.com/kevinchittilapilly) | | [Nour Grati](https://github.com/Nour-Grati)
| Tunisia | Python | [Leetcode](https://leetcode.com/nourgrati/)
[Hackerrank](https://www.hackerrank.com/noor_grati)
[Twitter](https://twitter.com/GratiNour1) -|[Avinash Trivedi](https://github.com/trivediavinash)
|India | C++ | [Leetcode](https://leetcode.com/avi_002/) | -|[Ishika Goel](https://github.com/ishikagoel5628)
| India | C++ | [Leetcode](https://leetcode.com/ishikagoel5628/) | -|[Prashansa Tanwar](https://github.com/prashansatanwar)
| India | C++ | [Leetcode](https://leetcode.com/prashansaaa/) | -|[Ishu Raj](https://github.com/ir2010)
| India | C++ | [Leetcode](https://leetcode.com/ishuraj2010/) | +| [Avinash Trivedi](https://github.com/trivediavinash)
| India | C++ | [Leetcode](https://leetcode.com/avi_002/) | +| [Ishika Goel](https://github.com/ishikagoel5628)
| India | C++ | [Leetcode](https://leetcode.com/ishikagoel5628/) | +| [Fenil Dobariya](https://github.com/ifenil)
| India | Java | [Github](https://github.com/ifenil) | +| [Prashansa Tanwar](https://github.com/prashansatanwar)
| India | C++ | [Leetcode](https://leetcode.com/prashansaaa/) | +| [Ishu Raj](https://github.com/ir2010)
| India | C++ | [Leetcode](https://leetcode.com/ishuraj2010/) | +