8000 3 problems · hitzzc/go-leetcode@4f21847 · GitHub
[go: up one dir, main page]

Skip to content

Commit 4f21847

Browse files
committed
3 problems
1 parent 918a893 commit 4f21847

File tree

4 files changed

+33
-1
lines changed

4 files changed

+33
-1
lines changed

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,10 @@ Golang solution for leetcode. For each problem, there is a simple *_test.go to t
230230
#### [313. Super Ugly Number](https://github.com/hitzzc/go-leetcode/tree/master/super_ugly_number)
231231
#### [315. Count of Smaller Numbers After Self](https://github.com/hitzzc/go-leetcode/tree/master/count_of_smaller_numbers_after_self)
232232
#### [316. Remove Duplicate Letters](https://github.com/hitzzc/go-leetcode/tree/master/remove_duplicate_letters)
233-
#### [318. Maximum Product of Word Lengths ](https://github.com/hitzzc/go-leetcode/tree/master/maximum_product_of_word_lengths)
233+
#### [318. Maximum Product of Word Lengths ](https://github.com/hitzzc/go-leetcode/tree/master/maximum_product_of_word_lengths)
234+
#### [319. Bulb Switcher](https://github.com/hitzzc/go-leetcode/tree/master/bulb_switcher)
235+
#### [322. Coin Change](https://github.com/hitzzc/go-leetcode/tree/master/coin_change)
236+
#### [326. Power of Three](https://github.com/hitzzc/go-leetcode/tree/master/power_of_three)
234237

235238

236239

bulb_switcher/bulb_switcher.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
class Solution {
2+
public:
3+
int bulbSwitch(int n) {
4+
int ret = 0;
5+
for (int i = 1; i*i <= n; ++i) {
6+
++ret;
7+
}
8+
return ret;
9+
}
10+
};

coin_change/coin_change.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
class Solution {
2+
public:
3+
int coinChange(vector<int>& coins, int amount) {
4+
vector<int> dp(amount+1, amount+1);
5+
dp[0] = 0;
6+
for (int i = 1; i < dp.size(); ++i) {
7+
for (auto coin: coins) {
8+
if (i >= coin) dp[i] = min(dp[i], dp[i-coin]+1);
9+
}
10+
}
11+
return dp.back() == amount+1 ? -1: dp.back();
12+
}
13+
};

power_of_three/power_of_three.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
class Solution {
2+
public:
3+
bool isPowerOfThree(int n) {
4+
return (n > 0 && 1162261467 % n == 0);
5+
}
6+
};

0 commit comments

Comments
 (0)
0