本文主要是介绍第184场周赛,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
文章目录
- 第184场周赛
- 1408. 数组中的字符串匹配
- 1409. 查询带键的排列
- 1410. HTML 实体解析器
第184场周赛
1408. 数组中的字符串匹配
java
class Solution {public List<String> stringMatching(String[] words) {List<String> res = new ArrayList<String> ();for(String s:words){int count = 0;for(String t:words){if(t.contains(s)){count++;}if(count>=2){res.add(s);break;}}}return res;}
}
c++
这里需要记住的是words[i].find(words[j])!=words[i].npos表示不包含j字符串
class Solution {
public:vector<string> stringMatching(vector<string>& words) {vector<string> res;int n = words.size();if(n==0) return res;int exist[n];memset(exist,0,sizeof(exist));for(int i=0;i<n;i++){if(exist[i]) continue;for(int j=0;j<n;j++){if(i==j || exist[j]) continue;if(words[i].find(words[j])!=words[i].npos){//找到了exist[j] = 1;res.push_back(words[j]);}}}return res;}
};
1409. 查询带键的排列
class Solution {public int[] processQueries(int[] queries, int m) {int len = queries.length;int [] res = new int[len];Stack<Integer> queue = new Stack<Integer>();Stack<Integer> stack = new Stack<Integer>();for(int i=m;i>=1;i--){queue.add(i);}
// System.out.println("init:"+queue.toString());for(int j=0;j<queries.length;j++){int cur = queries[j];while(queue.peek()!=cur){int top = queue.pop();
// System.out.print("top:"+top);stack.add(top);}if(queue.peek()==cur){queue.pop();int step = 0;while(!stack.isEmpty()){int top = stack.pop();queue.add(top);step++;}queue.add(cur);res[j]=step;}// System.out.println(queue.toString());}return res;}
}
1410. HTML 实体解析器
这里需要注意的就是maps.put("&", “&”);放在最后,不然>这个用例会过不了
class Solution {public String entityParser(String text) {Map<String,String> maps = new LinkedHashMap<String,String>();maps.put(""", "\"");maps.put("'", "'");maps.put(">", ">");maps.put("<", "<");maps.put("⁄", "/");maps.put("&", "&");for(Map.Entry<String,String> t:maps.entrySet()){
// System.out.println(t.getKey());if(text.contains(t.getKey())){
// System.out.println("true!!!");text = text.replaceAll(t.getKey(), t.getValue());}}return text;}
}
这篇关于第184场周赛的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!