Created
May 24, 2019 12:39
-
-
Save kangchihlun/24ee01afcfa96424ef19698401ab19b6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static void Main(string[] args) | |
{ | |
// getMostVisited(10, new List<int>() { 1, 5 ,10,3}); | |
longestPalindrome(7, "bandana"); | |
} | |
public static int getMostVisited(int n, List<int> sprints) | |
{ | |
int ret = -1; | |
if (sprints.Count < 1) | |
return ret; | |
if (n < 1) | |
return ret; | |
// generate table | |
List<List<int>> table = new List<List<int>>(); // index => passing count | |
List<int> scores = new List<int>(new int[n]); | |
for (int j = 0; j < sprints.Count - 1; j++) | |
{ | |
List<int> row = new List<int>(new int[n]); | |
table.Add(row); // init score count | |
} | |
int rowCnt = 0; | |
for (int j = 0; j < sprints.Count-1; j++) | |
{ | |
List<int> row = table[rowCnt]; | |
bool bForward = sprints[j] <= sprints[j + 1]; | |
if (bForward) | |
{ | |
for(int m = sprints[j]; m <= sprints[j + 1];m++) | |
{ | |
row[m-1] = 1; | |
} | |
} | |
else | |
{ | |
for (int m = sprints[j]; m >= sprints[j + 1]; m--) | |
{ | |
row[m-1] = 1; | |
} | |
} | |
rowCnt++; | |
} | |
for (int m = 0; m < n; m++) | |
{ | |
for (int k = 0; k < table.Count; k++) | |
{ | |
scores[m] += table[k][m]; | |
} | |
} | |
ret = scores.IndexOf(scores.Max())+1; | |
return ret; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
第五題題目備忘,基本上就是在問狗狗跑旗標(有方向性),統計哪個號碼經過最多次訪問。