public static String compressString(String str) {
		if (str == null) {
			throw new IllegalArgumentException("str cannot be null");
		}
		if (str.isEmpty()) {
			return str;
		}
		StringBuilder sb = new StringBuilder();
		char lastChar = str.charAt(0);
		sb.append(lastChar);
		int sameCharsAmount = 1;
		for (int i = 1; i < str.length(); i++) {
			if (str.charAt(i) == lastChar) {
				sameCharsAmount++;
			} else {
				sb.append(sameCharsAmount);
				lastChar = str.charAt(i);
				sb.append(lastChar);
				sameCharsAmount = 1;
			}
		}
		sb.append(sameCharsAmount);
		if (sb.length() < str.length()) {
			return sb.toString();
		}
		return str;
	}