Class Solution

java.lang.Object
g0701_0800.s0767_reorganize_string.Solution

public class Solution extends java.lang.Object
767 - Reorganize String.

Medium

Given a string s, rearrange the characters of s so that any two adjacent characters are not the same.

Return any possible rearrangement of s or return "" if not possible.

Example 1:

Input: s = “aab”

Output: “aba”

Example 2:

Input: s = “aaab”

Output: ""

Constraints:

  • 1 <= s.length <= 500
  • s consists of lowercase English letters.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    java.lang.String
    reorganizeString(java.lang.String s)
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • reorganizeString

      public java.lang.String reorganizeString(java.lang.String s)