290. 单词规律
问题描述:
代码:
class Solution { public boolean wordPattern(String pattern, String s) { char []p=pattern.toCharArray(); Maphx = new HashMap<>(); String[] arr = s.split(" "); if(p.length!=arr.length) return false; for(int i=0;i 思路:
String[] arr = s.split(" "); 根据空格来分割字符串
哈希containsValues
HashMap yyds!
763. 划分字母区间
问题描述:
代码:
class Solution { public ListpartitionLabels(String s) { int n=s.length(); int []ans=new int[26]; for (int i = 0; i < n; i++) { ans[s.charAt(i) - 'a'] = i; } int start = 0, end = 0; List list = new linkedList<>(); for (int i = 0; i < n; i++) { end = Math.max(end, ans[s.charAt(i) - 'a']); if (i == end) { list.add(end - start + 1); start = end + 1; } } return list; } } 思路:
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)