> For the complete documentation index, see [llms.txt](https://timmybeeflin.gitbook.io/cracking-leetcode/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://timmybeeflin.gitbook.io/cracking-leetcode/greedy/lintcode-1871-maximum-moment.md).

# lintcode 1871 · Maximum moment

{% embed url="<https://www.lintcode.com/problem/1871>" %}

![](/files/56o41jeekgQfXg7FflG3)

time: O(1)

space: O(1)

```java
public class Solution {
    /**
     * @param time: a string of Time
     * @return: The MaximumMoment
     */
    public String MaximumMoment(String time) {
        char[] charAry = time.toCharArray();

        if (charAry[0] == '?') {
            if (charAry[1] >= '4' && charAry[1] <= '9') {
                charAry[0] = '1';
            } else {
                charAry[0] = '2'; // charAry[1] == '?' also give charAry[0] = '2'
            }
        }
        if (charAry[1] == '?') {
            if (charAry[0] != '2') {
                charAry[1] = '9';
            } else {
                charAry[1] = '3';
            }
        }
        charAry[3] = (charAry[3] == '?') ? '5' : charAry[3];
        charAry[4] = (charAry[4] == '?') ? '9' : charAry[4];
        
        return String.valueOf(charAry);
    }
}j
```
