This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Solution { | |
public: | |
int integerBreak(int n) { | |
vector<int> dp(n + 1, 0); | |
dp[1] = 1; | |
dp[2] = 1; | |
for(int i = 3; i <= n; i++){ | |
for(int j = 2; j < i; j++){ | |
// divide into parts | |
int left = max(j, dp[j]); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Solution { | |
public: | |
vector<TreeNode*> generateTrees(int n) { | |
vector<vector<TreeNode*>> dp(n + 1, vector<TreeNode*>()); | |
dp[0].push_back(nullptr); | |
dp[1].push_back(new TreeNode(1)); | |
for(int i = 2; i <= n; i++){ | |
// root selection | |
for(int j = 1; j <= i; j++){ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Solution { | |
public: | |
int numTrees(int n) { | |
vector<int> dp(n + 1, 0); | |
dp[0] = 1; | |
dp[1] = 1; | |
for(int i = 2; i <= n; i++){ | |
int avail = i - 1; | |
for(int j = 0; j < i; j++){ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Solution { | |
public: | |
using lli = long long int; | |
int M = (int) 1e9 + 7; | |
int lengthAfterTransformations(string s, int t) { | |
array<int, 26> freq{}; | |
for(char c : s) freq[c - 'a']++; | |
while(t >= 26){ | |
array<lli, 26> temp{}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Solution { | |
public: | |
int combinationSum4(vector<int>& coins, int amount) { | |
int n = coins.size(); | |
vector<unsigned int> curr(amount + 1, 0); | |
curr[0] = 1; | |
for(int j = 1; j <= amount; j++){ | |
for(int coin : coins){ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Solution { | |
public: | |
using lli = long long; | |
int change(int amount, vector<int>& coins) { | |
int n = coins.size(); | |
vector<unsigned int> curr(amount + 1, 0); | |
curr[0] = 1; | |
for(int coin : coins){ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Solution { | |
public: | |
int coinChange(vector<int>& coins, int amount) { | |
int n = coins.size(); | |
vector<int> curr(amount + 1, amount + 1); | |
curr[0] = 0; | |
for(int coin : coins){ | |
// (0, coin - 1) => already have coorect values |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { zodResolver } from "@hookform/resolvers/zod"; | |
import React from "react"; | |
import { useForm } from "react-hook-form"; | |
import { z } from "zod"; | |
const schema = z.object({ | |
description: z.string().min(10, "min length of description is 10"), | |
}); | |
const TaskForm = () => { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Solution { | |
public: | |
int findTargetSumWays(vector<int>& nums, int target) { | |
int n = nums.size(); | |
int sum = accumulate(nums.begin(), nums.end(), 0); | |
if(sum < abs(target)) return 0; | |
// (-sum, sum) => (0, 2 * sum) | |
int dp[21][10001] = {}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Solution { | |
public: | |
bool canPartition(vector<int>& nums) { | |
int sum = accumulate(nums.begin(), nums.end(), 0); | |
if(sum % 2 == 1) return false; | |
int target = sum / 2; | |
bitset<200 * 100 + 1> dp; | |
dp[0] = 1; | |
for(int num : nums){ |
NewerOlder