注册一亩三分地论坛,查看更多干货!
您需要 登录 才可以下载或查看附件。没有帐号?注册账号
x
1. 把url输入进浏览器跳转网页的过程发生了什么
2.process之间怎么交流
3.http和https有什么区别?
4.process和thread有什么区别?
5.有什么design pattern
6.写一下java singleton
- // not thread safe. 1point 3 acres
- public class Singleton {
- private static Singleton instance;
- private Singleton (){} . Waral dи,
-
- public static Singleton getInstance() {
- if (instance == null) {
- instance = new Singleton();
- }
- return instance;
- }
- }
复制代码
- // thread safe
- public class Singleton {
- private static Singleton instance;
- private Singleton (){} . .и
- public static synchronized Singleton getInstance() { . check 1point3acres for more.
- if (instance == null) {
- instance = new Singleton(); .--
- }
- return instance;
- }
- }
复制代码 . From 1point 3acres bbs
写一下atoi
- ublic int myAtoi(String str) {. Χ
- // if input string is empty, return 0
- if (str == null || str.isEmpty())
- return 0;
- // save input string size
- int n = str.length();. Χ
- // skip spaces
- int index = 0;
- while (index < n && str.charAt(index) == ' ') {
- index++;
- }-baidu 1point3acres
- // reached the end of string, return 0
- if (index == n)
- return 0;
- // calculate sign
- int sign = str.charAt(index) == '-' ? -1 : 1;
- // move to next char if sign is present
- if (str.charAt(index) == '-' || str.charAt(index) == '+') {
- index++;. 1point3acres
- }. From 1point 3acres bbs
- // reached the end of string, return 0. Waral dи,
- if (index == n)
- return 0;
- . 1point3acres.com
- // calculate max value without last digit
- // -2,147,483,647 -> -2,147,483,64
- int max = Integer.MAX_VALUE / 10;
- // calculate last digit
- // 2,147,483,647 -> 7 or -2,147,483,648 -> 8
- int lastMaxDigit = sign > 0 ? Integer.MAX_VALUE - max * 10 : -(Integer.MIN_VALUE + max * 10);. 1point 3 acres
- // result without sign
- int number = 0;
- // loop until end or until character is digit
- while (index < n && str.charAt(index) >= '0' && str.charAt(index) <= '9') {. 1point3acres
- // convert character to digit
- int digit = str.charAt(index) - '0';
- // if number is greater than max without last digit
- // or number is equal max without last digit but last digit is greater then max last digit
- // return integer max or min, depend on sign. From 1point 3acres bbs
- if (number > max || number == max && digit >= lastMaxDigit) {
- return sign > 0 ? Integer.MAX_VALUE : Integer.MIN_VALUE;
- }. Χ
- // accumulate current digit to result. .и
- number = number * 10 + digit;
- // move to next character
- index++;
- }
- // add sign to number and return result.--
- return sign * number;
- }
复制代码
.
补充内容 (2019-8-20 15:39):
附一个楼主准备面试的时候从newcoder爬下来的面经:
https://docs.google.com/document ... jU/edit?usp=sharing |