Class Solution

java.lang.Object
g1401_1500.s1417_reformat_the_string.Solution

public class Solution extends Object
1417 - Reformat The String.<p>Easy</p> <p>You are given an alphanumeric string <code>s</code>. ( <strong>Alphanumeric string</strong> is a string consisting of lowercase English letters and digits).</p> <p>You have to find a permutation of the string where no letter is followed by another letter and no digit is followed by another digit. That is, no two adjacent characters have the same type.</p> <p>Return <em>the reformatted string</em> or return <strong>an empty string</strong> if it is impossible to reformat the string.</p> <p><strong>Example 1:</strong></p> <p><strong>Input:</strong> s = &ldquo;a0b1c2&rdquo;</p> <p><strong>Output:</strong> &ldquo;0a1b2c&rdquo;</p> <p><strong>Explanation:</strong> No two adjacent characters have the same type in &ldquo;0a1b2c&rdquo;. &ldquo;a0b1c2&rdquo;, &ldquo;0a1b2c&rdquo;, &ldquo;0c2a1b&rdquo; are also valid permutations.</p> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> s = &ldquo;leetcode&rdquo;</p> <p><strong>Output:</strong> &quot;&quot;</p> <p><strong>Explanation:</strong> &ldquo;leetcode&rdquo; has only characters so we cannot separate them by digits.</p> <p><strong>Example 3:</strong></p> <p><strong>Input:</strong> s = &ldquo;1229857369&rdquo;</p> <p><strong>Output:</strong> &quot;&quot;</p> <p><strong>Explanation:</strong> &ldquo;1229857369&rdquo; has only digits so we cannot separate them by characters.</p> <p><strong>Constraints:</strong></p> <ul> <li><code>1 <= s.length <= 500</code></li> <li><code>s</code> consists of only lowercase English letters and/or digits.</li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details