Created
January 11, 2019 14:53
-
-
Save zhiweio/6db06726a7adbbd2eb232c279d75983b to your computer and use it in GitHub Desktop.
青芒 笔试题解
This file contains hidden or 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
| #!/usr/bin/env python3 | |
| # -*- coding: utf-8 -*- | |
| ''' | |
| question1: | |
| 大整数加法 | |
| ''' | |
| def add(num1, num2): | |
| """ | |
| :type num1: str | |
| :type num2: str | |
| :rtype: str | |
| """ | |
| res = "" | |
| m = len(num1) | |
| n = len(num2) | |
| i = m - 1 | |
| j = n - 1 | |
| flag = 0 | |
| while i >= 0 or j >= 0: | |
| a = int(num1[i]) if i >= 0 else 0 | |
| i = i - 1 | |
| b = int(num2[j]) if j >= 0 else 0 | |
| j = j - 1 | |
| sum = a + b + flag | |
| res = str(sum % 10) + res | |
| flag = sum // 10 | |
| return res if flag == 0 else (str(flag) + res) | |
| ''' | |
| question2: | |
| 如果一个 Java 服务,出现了频繁的 Full GC,你会从哪些方面尝试定位和解决对应的问题? | |
| answer: | |
| 很抱歉我平时没怎么用 java 开发,对这个问题不熟悉 | |
| Google 到一篇很好的文章 https://gitbook.cn/books/5a464546d06cae3d240f25a6/index.html | |
| ''' | |
| ''' | |
| question3: | |
| 我们在实际业务处理中,总会碰上各种编码格式的字符串信息,比如中文、Emoji,等等,在 python 中,对不同编码字符串进行处理的时候有哪些特别注意的问题和相关的处理经验? | |
| answer: | |
| 1. 使用 Python3, Python3 把系统默认编码设置为 UTF-8 | |
| 2. 注解 "# -*- coding: utf-8 -*-", 表示按照UTF-8编码读取源代码 | |
| 3. 注意区分文本字符和二进制数据,Py3中分别用 str 和 bytes 表示。文本字符全部用 str 类型表示,str 能表示 Unicode 字符集中所有字符,而二进制字节数据用一种全新的数据类型,用 bytes 来表示 | |
| bytes 类型可以是 ASCII范围内的字符和其它十六进制形式的字符数据,但不能用中文等非ASCII字符表示 | |
| 4. str <-> bytes | |
| ---------- ---------- | |
| | | <------ decode -------- | | | |
| | str | (assic,utf-8,gbk...) | bytes | | |
| | | ------- encode -------> | | | |
| ---------- ---------- | |
| 5. 不同的操作系统中字符编码是不一样的,要注意 | |
| 6. 确保你的编辑器(IDE)使用正确的编码 | |
| 7. 操作系统、编辑器(IDE)、文件使用统一的编码 | |
| ''' | |
| if __name__ == '__main__': | |
| ans = add('123456789', '123456789') | |
| print(ans) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment