---
# System prepended metadata

title: 2745. Construct the Longest New String
tags: [Leetcode, Medium, Math]

---

Link: https://leetcode.com/problems/construct-the-longest-new-string/description/
## 思路
z的个数有多少都不重要
如果xy数量一样 有多少用多少
否则数量小的那个可以都用掉 但数量多的只能多用一个
## Code
```python=
class Solution:
    def longestString(self, x: int, y: int, z: int) -> int:
        minVal = min(x, y)
        if x==y:
            return x*4+z*2
        else:
            return minVal*4+2+z*2
```