当前位置:首页>正文

leetcode第三题,JAVA小白求教 python leetcode 上一道题 22 生成所有括号组合

2023-05-08 07:47:31 互联网 未知

leetcode第三题,JAVA小白求教

public int lengthOfLongestSubstring(String s) {
if (s.length()==0) return 0
HashMapmap = new HashMap() int max=0 for (int i=0, j=0 i if (map.containsKey(s.charAt(i))){ j = Math.max(j,map.get(s.charAt(i)) 1) } map.put(s.charAt(i),i) max = Math.max(max,i-j 1) } return max }

python leetcode 上一道题 22 生成所有括号组合

那要看你代码写的兼容不兼容了, 比如在linux中文件目录和windows中是不一样的,你如果把路径这些东西硬编码了,那可能就会有点小问题,稍微注意一下就行了,python是跨平台的

leetcode 中 java 版本的代码 怎么提交

不能写main函数,你需要的是按照class Solution给的接口来实现它的一个成员函数

给一个参考答案

111111#include using namespace std class Solution { public: void reverseWords(string &s) { string ans = "", temp stringstream sin(s) while(sin >> temp) { if(ans != "") { ans = temp " " ans } else { ans = temp } } s = ans } }