It's the Xinrui Ma

# Blog

## 322. Coin Change – JavaScript Solution

Posted by in LeetCode on

You are given coins of different denominations and a total amount of money amount. Write a function to compute the fewest number of coins that you need to make up that amount. If that amount of money cannot be made up by any combination of the coins, return `-1`.

Example 1:

Input: coins = `[1, 2, 5]`, amount = `11`
Output: `3`
Explanation: 11 = 5 + 5 + 1

Example 2:

Input: coins = `[2]`, amount = `3`
Output: -1

Note:
You may assume that you have an infinite number of each kind of coin.

OK， 接下来想想转化公示；

DP[i] = Math.min(DP[i], DP[i – coin] + 1)

Solution:

## Longest Palindromic Substring

Posted by in LeetCode on

Given a string s, find the longest palindromic substring in s. You may assume that the maximum length of s is 1000.

Example 1:

```Input: "babad"
Output: "bab"
Note: "aba" is also a valid answer.```

Example 2:

```Input: "cbbd"
Output: "bb"```

Solution 1:
Use O(N) time complexity and O(1) space complexity to find the palindromic.
Start from the longest possible substring, once it find a match, return that result