<2017年6月>
28293031123
45678910
11121314151617
18192021222324
2526272829301
2345678

统计

  • 随笔 - 57
  • 文章 - 7
  • 评论 - 0
  • 引用 - 0

常用链接

留言簿

随笔分类

随笔档案

文章分类

文章档案

Blog

Coder 必备技巧

Compiler for Wurq

搜索

  •  

最新评论

阅读排行榜

评论排行榜

【LeeCode 2017/06/26】14. Longest Common Prefix
 1 class Solution {
 2 public:
 3     string longestCommonPrefix(vector<string>& strs) {
 4         int count = strs.size();
 5         int prt_ch[300= {0};
 6 
 7         int max_len = 0;
 8         for(int i=0;i<count;i++){
 9             max_len = max_len >= strs[i].length()? max_len:strs[i].length();
10         }
11         vector<vector<int>>prt_str;
12         prt_str.resize(max_len);
13         for (int i = 0; i < max_len; i++) {
14             prt_str[i].resize(300);
15         }
16 
17         for (int i = 0; i < count; i++){
18             for (int j = 0;j < strs[i].length(); j++){
19                 prt_str[j][strs[i][j]]++;
20             }
21         }
22         string ans = "";
23         if (count <= 0)
24             return ans;
25             
26         for (int i = 0; i < strs[0].length(); i++){
27             if (prt_str[i][strs[0][i]] == count)
28                 ans += strs[0][i];
29             else
30                 break;
31         }
32         return ans;
33     }
34 };
35 

posted on 2017-06-26 17:13 Wurq 阅读(106) 评论(0)  编辑 收藏 引用 所属分类: 【LeeCode 每日N题】


只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理