You are viewing a single comment's thread. Return to all comments →
You don't need to create HashMap. ASCI code is basically already HashMap. I think this code is much more simplier
import java.io.*; import java.util.*; import java.text.*; import java.math.*; import java.util.regex.*; public class Solution { public static void main(String[] args) { Scanner in = new Scanner(System.in); int n = 26; int h[] = new int[n]; for (int h_i = 0; h_i < n; h_i++) { h[h_i] = in.nextInt(); } String word = in.next(); int lengh = word.length(); int max = 0; for (int i = 0; i < lengh; i++) { char tempChar = word.charAt(i); max = max < h[tempChar - 97] ? h[tempChar - 97] : max; } System.out.println(max * lengh); } }
Seems like cookies are disabled on this browser, please enable them to open this website
Designer PDF Viewer
You are viewing a single comment's thread. Return to all comments →
You don't need to create HashMap. ASCI code is basically already HashMap. I think this code is much more simplier