Skip to content

Instantly share code, notes, and snippets.

@fsword
Created September 23, 2013 19:23
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save fsword/6675566 to your computer and use it in GitHub Desktop.
左耳朵耗子的面试题StrToInt 举例(没涉及场景,因此先用最简单的方式实现,不考虑字符串超长等情况)
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;
}
}
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