---
# System prepended metadata

title: 63. Unique Paths II
tags: [DP]

---

---
title: 63. Unique Paths II
tags: DP
description: share source code.
---

# 63. Unique Paths II

```java=
class Solution {
    public String longestPalindrome(String s) {
        int n = s.length();
        int dp[][] = new int [n][n];
        int start = 0;
        int end = 0;
        int len = 1;
        for(int i = n - 1; i >= 0; i--){
           for(int j = i; j < n; j++){
            if(i == j){
                dp[i][j] = 1;
            }else if(s.charAt(i) == s.charAt(j) && (j - i == 1 || dp[i + 1][ j - 1] > 0) ){
                dp[i][j] = Math.max(dp[i][j], dp[i + 1][ j - 1] + 2);
                len = Math.max(len, dp[i][j]);
                if( dp[i][j] ==  len){
                    
                   start = i; 
                   end = j; 
                 
                }
            }
          } 
        }
        System.out.println(len);
        
        return s.substring(start, start + len);             
    }
}
```

