JAVA_Shortest Distance to a Character_LeetCode 821


JAVA_Shortest Distance to a Character_LeetCode 821

JAVA_Shortest Distance to a Character_LeetCode 821 풀이 class Solution { public int[] shortestToChar(String s, char c) { int[] res = new int[s.length()]; for (int i = 0, j = 0; i < res.length; i++) { if (i == 0) j = s.indexOf(c); if (i > j && s.indexOf(c, i) >= 0 && Math.abs(j - i) > Math.abs(s.indexOf(c, i) - i)) { j = s.indexOf(c, i); } res[i] = Math.abs(j - i); } return res; } } * 출처 Shortest Distance to a Character - LeetCode Can you solve this real interview question? Shortest Distance to a C...


#JAVA #JAVA_LeetCode821 #JAVA_ShortestDistancetoaCharacter #JAVA_ShortestDistancetoaCharacter_LeetCode821 #ShortestDistancetoaCharacter_LeetCode821

원문링크 : JAVA_Shortest Distance to a Character_LeetCode 821