Created
September 23, 2013 19:23
-
-
Save fsword/6675566 to your computer and use it in GitHub Desktop.
左耳朵耗子的面试题StrToInt 举例(没涉及场景,因此先用最简单的方式实现,不考虑字符串超长等情况)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Misc { | |
public static int[] StrToInt(String str) { | |
if(str == null) return new int[0]; | |
int[] array = new int[str.codePointCount(0,str.length())]; | |
for(int i=0; i < array.length; i++){ | |
array[i] = str.codePointAt(i); | |
} | |
return array; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def StrToInt str | |
str.nil? ? [] : str.unpack('U*') | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment