9.25 Unity笔试AK代码
1.
public int minEditCost (String str1, String str2, int ic, int dc, int rc) { int len1 = str1.length(); int len2 = str2.length(); int[][] dp = new int[len1 + 1][len2 + 1]; for (int i = 0; i <= len1; i++) { dp[i][0] = i * dc; } for (int j = 0; j <= len2; j++) { dp[0][j] = j * ic; } for (int i = 1; i <= len1; i++) { for (int j = 1; j <= len2; j++) { if (str1.charAt(i - 1) == str2.charAt(j - 1)) { dp[i][j] = dp[i - 1][j -1]; } else { dp[i][j] = Math.min(dp[i - 1][j - 1] + rc, Math.min(dp[i - 1][j] + dc, dp[i][j - 1] + ic)); } } } return dp[len1][len2]; }2.
public String sum (String a, String b) { Integer sum1 = Integer.parseInt(a); Integer sum2 = Integer.parseInt(b); return String.valueOf(sum1 + sum2); }3.
int res = -1; public int longestCycle (int[] edges) { boolean[] flags = new boolean[edges.length]; for (int i = 0; i < edges.length; i++) { if (!flags[i]) { dfs(edges, flags, i, 0); } } return res; } private int[] dfs(int[] edges, boolean[] flags, int cur, int sum) { int[] temp = {-1, sum}; if (cur == -1) { return temp; } if (flags[cur]) { temp[0] = cur; return temp; } flags[cur] = true; int[] num = dfs(edges, flags, edges[cur], sum + 1); if (num[0] == cur) { res = Math.max(res, num[1] - sum); } return num; }感觉还行,现在写笔试写太多了,已经累了