Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,24 @@
"iomanip": "cpp",
"sstream": "cpp",
"source_location": "cpp",
"any": "cpp"
"any": "cpp",
"csetjmp": "cpp",
"csignal": "cpp",
"cfenv": "cpp",
"chrono": "cpp",
"codecvt": "cpp",
"complex": "cpp",
"condition_variable": "cpp",
"cuchar": "cpp",
"forward_list": "cpp",
"ratio": "cpp",
"fstream": "cpp",
"future": "cpp",
"mutex": "cpp",
"scoped_allocator": "cpp",
"shared_mutex": "cpp",
"thread": "cpp",
"typeindex": "cpp"
},
"cSpell.words": [
"atoi",
Expand Down
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,17 @@ This is a repository for my solutions to Leetcode problems written in C, C++, Py
| 105| [Recover a Tree From Preorder Traversal](https://leetcode.com/problems/recover-a-tree-from-preorder-traversal/) | Hard | [C++](recover-a-tree-from-preorder-traversal/main.cpp) | [Doxygen](https://milosz275.github.io/leetcode/recover-a-tree-from-preorder-traversal/) | ✔️ |
| 106| [Maximum Subarray](https://leetcode.com/problems/maximum-subarray/) | Medium | [C++](maximum-subarray/main.cpp) | [Doxygen](https://milosz275.github.io/leetcode/maximum-subarray/) | ✔️ |
| 107| [Maximum Absolute Sum of Any Subarray](https://leetcode.com/problems/maximum-absolute-sum-of-any-subarray/) | Medium | [C++](maximum-absolute-sum-of-any-subarray/main.cpp) | [Doxygen](https://milosz275.github.io/leetcode/maximum-absolute-sum-of-any-subarray/) | ✔️ |
| 108| [Graph Valid Tree](https://leetcode.com/problems/graph-valid-tree/) | Medium | [C++](graph-valid-tree/main.cpp) | [Doxygen](https://milosz275.github.io/leetcode/graph-valid-tree/) | ✔️ |
| 109| [Merge Two 2D Arrays by Summing Values](https://leetcode.com/problems/merge-two-2d-arrays-by-summing-values/) | Easy | [C++](merge-two-2d-arrays-by-summing-values/main.cpp) | [Doxygen](https://milosz275.github.io/leetcode/merge-two-2d-arrays-by-summing-values/) | ✔️ |
| 110| [Min Stack](https://leetcode.com/problems/min-stack/) | Medium | [C++](min-stack/main.cpp) | [Doxygen](https://milosz275.github.io/leetcode/min-stack/) | ✔️ |
| 111| [Lowest Common Ancestor of a Binary Search Tree](https://leetcode.com/problems/lowest-common-ancestor-of-a-binary-search-tree/) | Medium | [C++](lowest-common-ancestor-of-a-binary-search-tree/main.cpp) | [Doxygen](https://milosz275.github.io/leetcode/lowest-common-ancestor-of-a-binary-search-tree/) | ✔️ |
| 112| [Implement Trie (Prefix Tree)](https://leetcode.com/problems/implement-trie-prefix-tree/) | Medium | [C++](implement-trie-prefix-tree/main.cpp) | [Doxygen](https://milosz275.github.io/leetcode/implement-trie-prefix-tree/) | ✔️ |
| 113| [Reverse Nodes in k-Group](https://leetcode.com/problems/reverse-nodes-in-k-group/) | Hard | [C++](reverse-nodes-in-k-group/main.cpp) | [Doxygen](https://milosz275.github.io/leetcode/reverse-nodes-in-k-group/) | ✔️ |
| 114| [Partition Array According to Given Pivot](https://leetcode.com/problems/partition-array-according-to-given-pivot/) | Medium | [C++](partition-array-according-to-given-pivot/main.cpp) | [Doxygen](https://milosz275.github.io/leetcode/partition-array-according-to-given-pivot/) | ✔️ |
| 115| [Check if Number is a Sum of Powers of Three](https://leetcode.com/problems/check-if-number-is-a-sum-of-powers-of-three/) | Medium | [C++](check-if-number-is-a-sum-of-powers-of-three/main.cpp) | [Doxygen](https://milosz275.github.io/leetcode/check-if-number-is-a-sum-of-powers-of-three/) | ✔️ |
| 116| [Count Total Number of Colored Cells](https://leetcode.com/problems/count-total-number-of-colored-cells/) | Medium | [C++](count-total-number-of-colored-cells/main.cpp) | [Doxygen](https://milosz275.github.io/leetcode/count-total-number-of-colored-cells/) | ✔️ |
| 117| [Find Missing and Repeated Values](https://leetcode.com/problems/find-missing-and-repeated-values/) | Easy | [C++](find-missing-and-repeated-values/main.cpp) | [Doxygen](https://milosz275.github.io/leetcode/find-missing-and-repeated-values/) | ✔️ |
| 118| [Search a 2D Matrix](https://leetcode.com/problems/search-a-2d-matrix/) | Medium | [C](search-a-2d-matrix/main.c) | [Doxygen](https://milosz275.github.io/leetcode/search-a-2d-matrix/) | ✔️ |
<!-- This marks table end for milosz275.github.io/leetcode scraper -->

## License
Expand Down
2,924 changes: 2,924 additions & 0 deletions check-if-number-is-a-sum-of-powers-of-three/Doxyfile

Large diffs are not rendered by default.

12 changes: 12 additions & 0 deletions check-if-number-is-a-sum-of-powers-of-three/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
CC=g++
CFLAGS=-Wall -Werror -pedantic -Wextra -fsanitize=address -g
TARGET=build/main

all: $(TARGET)

$(TARGET): main.cpp
mkdir -p build
$(CC) $(CFLAGS) main.cpp -o $(TARGET)

clean:
rm -rf build/
40 changes: 40 additions & 0 deletions check-if-number-is-a-sum-of-powers-of-three/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# 1780. Check if Number is a Sum of Powers of Three

## Difficulty

Medium

## Question

Given an integer n, return true if it is possible to represent n as the sum of distinct powers of three. Otherwise, return false.

An integer y is a power of three if there exists an integer x such that y == 3x.

**Example 1:**

Input: n = 12
Output: true
Explanation: 12 = 3^1 + 3^2

**Example 2:**

Input: n = 91
Output: true
Explanation: 91 = 3^0 + 3^2 + 3^4

**Example 3:**

Input: n = 21
Output: false

**Constraints:**

1 <= n <= 107

## Link

[Check if Number is a Sum of Powers of Three](https://leetcode.com/problems/check-if-number-is-a-sum-of-powers-of-three/)

## Solution

Solution checks for 2 in ternary n representation.
25 changes: 25 additions & 0 deletions check-if-number-is-a-sum-of-powers-of-three/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#include <bits/stdc++.h>

using namespace std;

class Solution
{
public:
bool checkPowersOfThree(int n)
{
while (n > 0)
{
int remainder = n % 3;
if (remainder == 2)
return false;
n /= 3;
}
return true;
}
};

int main()
{
cout << "output: " << Solution().checkPowersOfThree(12) <<'\n';
return 0;
}
Loading