Menu Sidebar
Menu

hashing

[LintCode] Subarray Sum

public ArrayList<Integer> subarraySum(int[] nums) { // write your code here ArrayList<Integer> res = new ArrayList<Integer>(); if(nums.length == 0 || nums == null) return res; HashMap<Integer,Integer> map = new HashMap<Integer,Integer>(); int sum = 0; for(int i = 0 ; i < nums.length; i++) { sum += nums[i]; if(nums[i] == 0){ res.add(i); res.add(i); break; } if(sum == […]

[LintCode] Anagrams

public List<String> anagrams(String[] strs) { // write your code here List<String> res = new ArrayList<String>(); if(strs.length == 0 || strs == null) return res; HashMap<Integer,ArrayList<String>> maps = new HashMap<Integer,ArrayList<String>>(); for(int i = 0 ; i < strs.length; i++) { String s = strs[i]; int[] count = new int[26]; for(int j = 0; j < s.length(); […]

[LintCode] Compare Strings

public boolean compareStrings(String A, String B) { // write your code here int[] count_A = new int[26]; for(int i = 0; i < A.length(); i++) count_A[A.charAt(i)-‘A’]++; int[] count_B = new int[26]; for(int i = 0; i < B.length(); i++) count_B[B.charAt(i)-‘A’]++; for(int i = 0 ; i < 26; i++) { if(count_A[i]<count_B[i]) return false; } return […]

[LintCode] Two Strings Are Anagrams

public boolean anagram(String s, String t) { // write your code here s = s.toLowerCase(); t = t.toLowerCase(); int[] count_s = new int[26]; for(int i = 0; i < s.length(); i++){ if(s.charAt(i) == ‘ ‘) continue; count_s[s.charAt(i)-‘a’]++; } int[] count_t = new int[26]; for(int i = 0; i < t.length(); i++){ if(t.charAt(i) == ‘ ‘) […]

Codeforces Round #313 (Div. 2) D. Equivalent Strings

原题:http://codeforces.com/contest/560/problem/D 题目大意: 给字符串a和b, 定义a和b是等价的,如果: a和b相等. a等分成a1,a2,b等分成b1,b2, (a1==b1 && a2==b2) || (a2==b1 && a1==b2) 分析: 就暴呗…我也不知道为什么我暴就报错, 是因为java的原因么, 我看人家同样码用c++, 都飞快的. public void solve(int testNumber, InputReader in, OutputWriter out) { String a = in.readString(); String b = in.readString(); if (solve(a,b)) out.print(“YES”); else out.print(“NO”); } private boolean solve(String a, String b) { if (a.length() % 2 != 0 || […]

书脊

这青苔碧瓦堆, 俺曾睡风流觉, 将五十年兴亡看饱.

January 2023
M T W T F S S
 1
2345678
9101112131415
16171819202122
23242526272829
3031