Java:

```
int result = 0;
for (int i = 0; i < s.length(); result = result * 26 + (s.charAt(i) - 'A' + 1), i++);
return result;
```

C++:

```
int result = 0;
for (int i = 0; i < s.size(); result = result * 26 + (s.at(i) - 'A' + 1), i++);
return result;
```

Python:

```
return reduce(lambda x, y : x * 26 + y, [ord(c) - 64 for c in list(s)])
```

Python version is beautiful because reduce function and list comprehensive.

I don't know whether exist similar approach to achieve one line solution in Java or C++.

One possible way is defining another method like this:

```
public int titleToNumber(int num, String s)
```

to store previous result and make recursive call.

But this add much more lines.