[LeetCode]Remove Nth Node From End of List

原题Given a linked list, remove the n-th node from the end of list and return its head.ExampleGiven linked list: 1->2->3->4->5, and n = 2.After removing the second node from the end, the linked list becomes 1->2->3->5.NoteGiven n will always be valid.Follow upCould you do this in one pass思路首先,明确题意。题目给出了一个只有后继(successor),没有前驱(predecessor)的一个单向链表。要求删除倒数第n个节点。那么,思路自然会想到的就是在一次遍历就搞定题目要求。所以,我们自然要在遍历的过程中保存一... Read More

[LeetCode] 4 Sum

原题Given an array nums of n integers and an integer target, are there elements a, b, c, and d in nums such that a + b + c + d = target? Find all unique quadruplets in the array which gives the sum of target.NoteThe solution set must not contain duplicate quadruplets.ExampleGiven array nums = [1, 0, -1, 0, -2, 2], and target = 0.A solution set is[-1, 0, 0, 1][-2, -1, 1, 2][-2, 0, 0, 2题解本题的... Read More

[LeetCode]3Sum Closest

原题Given an array nums of n integers and an integer target, find three integers in nums such that the sum is closest to target. Return the sum of the three integers. You may assume that each input would have exactly one solution.ExampleGiven array nums = [-1, 2, 1, -4], and target = 1.The sum that is closest to the target is 2. (-1 + 2 + 1 = 2).思路本题目的解题思路和3Sum很像,区别在于3Sum求解的是三个数字和为target(即为0),然而3Su... Read More

滴滴出行业务平台研发岗位内推

有意者欢迎骚扰:huxu@didichuxing.co更新于:2018.05.25 15:5【在线业务研发工程师(PHP/Golang)我们需要一个这要的你有志于参与一场出行行业的变革;对于大流量高并发业务场景的技术挑战心潮澎湃。用你的代码影响成千上万人负责快车、专车、拼车、优步、优享、出租车等核心业务的服务端研发工作;负责接送机、站点拼车、跨城、小巴等垂直出行场景的服务建设和通勤、休娱、商旅等新出行场景孵化。【中台建设&中间件研发工程师/众里寻你千百度每一次将复杂世界变得简单都让你心花怒放;每一次你的系统都能云淡风轻跨越一座座流量洪峰,而你依然心若止水。你来协助我们提升生产力负责打磨现有产品业务流程,深入了解司乘两端业务,对出行场景进行抽象优化;负责出行中台&中间件架构设计和优化工作,提供新业务的快速扩展和接入能力。有意者欢迎骚扰:huxu@didichuxing.co... Read More

Python socket网络编程之阻塞与非阻塞模式

在智能家居项目hestia中,遇到一个关于python socket编程的小问题。发现在python socket客户端一端,在服务端断开时,没有抛出异常。[code lang="python"trymsg = _sFile.readline(except socket.error, elogging.info("socket exception" + e.message_reconnect([/code翻阅文档后,发现python socket分为阻塞式和非阻塞式。默认初始化的socket是阻塞式的,在阻塞式下,如果socket断开链接,将会返回空串。官方解释如下socket.setblocking(flagSet blocking or non-blocking mode of the socket: if flag is 0, the socket is set to... Read More

Python语言中循环引用(import)失败的解决方案

最近在开发智能家居项目hestia-rpi项目中,由于代码结构层级划分不合理,导致了循环引用(import)module失败的问题,错误如下[code lang="shell"Traceback (most recent call last)File "./main.py", line 8, in <module>from hestiarpi.library.server import serveFile "/home/pi/server/hestiarpi/library/server/server.py", line 4, in <module>from hestiarpi.library.brain import handleFile "/home/pi/server/hestiarpi/... Read More

Android O后台持续获取地理位置的简单调研过程

这几天打算重新捡起之前的智能家居项目,由于近期换了安卓设备,所以要重新开发一款安卓APP。但是其功能很简单---可以在后台稳定地上报地理位置到服务器。首先,考虑到用LocationManager方式获取地理位置,但是根据官方文档声明,很大程度上限制了后台获取位置的能力。重要说明:作为起点,我们只允许后台应用每小时接收几次位置更新。我们将在整个预览版阶段继续根据系统影响和开发者的反馈优化位置更新间隔。当然,根据官方解释,可以通过在通知区持续地显示一项通知信息,以提高后台获取位置更新的频率。但是由于自身对于安卓开发并不熟悉,而且网上高德提供的SDK已经很好地解决了该问题,索性直接高德定位SDK来解决吧。项目代码:https://github.com/GenialX/hestia-android/tree/v0.0.1_bet文章来源:胡小旭 => Android O后台持续获取地理位置... Read More

[LeetCode]3Sum

原题Given an array S of n integers, are there elements a, b, c in S such that a + b + c = 0? Find all unique triplets in the array which gives the sum of zero.Note: The solution set must not contain duplicate triplets.For example, given array S = [-1, 0, 1, 2, -1, -4]A solution set is[-1, 0, 1][-1, -1, 2题解暴力解法因为需要计算三个数字的总和,所以需要进行3层的遍历,故时间复杂度需要O(n^3),看来不可取,果断放弃。毕竟是medium难度的题,不至于这么个解法。two-pointes solutio... Read More

[LeetCode]Two Sum

原题Given an array of integers, return indices of the two numbers such that they add up to a specific target.You may assume that each input would have exactly one solution, and you may not use the same element twice.ExampleGiven nums = [2, 7, 11, 15], target = 9, Because nums[0] + nums[1] = 2 + 7 = 9, return [0, 1].题解暴力解法暴力解法使用两层for循环,遍历每一种存在的情况。[code lang="cpp"class Solution publicvector<int... Read More

[LeetCode]Palinkdrom Number

ProbleDetermine whether an integer is a palindrome. Do this without extra space.Some hints[code lang="shell" collapse="true"Could negative integers be palindromes? (ie, -1If you are thinking of converting the integer to string, note the restriction of using extra space.You could also try reversing an integer. However, if you have solved the problem "Reverse Integer", you know that th... Read More

[LeetCode]Roman to Integer

ProbleGiven a roman numeral, convert it to an integer.Input is guaranteed to be within the range from 1 to 3999.IdeaFinding the Law of Changing Roman Numbers into Arabic Numbers。Solutio[code lang="cpp"class Solution publicint romanToInt(string s) int l = s.length(), a = 0;for (int i = 0; i < l; ++iif (i < l - 1 && char2int(s[i]) < char2int(s[i + 1])) a -= char2int(s[i]);} else a += char2int(s[i]);... Read More

Git之替换代码库HTTP(s)地址路径成Git协议路径

当使用glide install安装go的依赖包时,会提示[INFO] --> Fetching github.com/xxx/yyUsername for 'https://github.com'此时,可以使用git config --add参数进行地址替换,具体命令如下git config --global --add url."git@github.com:".insteadOf "https://github.com/"之后,再使用glide install安装依赖包时,会使用如下形式的命令进行下载代码git clone git@github.com:xxx/yyy.gi文章来源:胡小旭 => Git之替换代码库HTTP(s)地址路径成Git协议路径 Read More

Mac(Linux)下解压(Unzip)文件时出现乱码解决方案

由于zip格式中并没有指定编码格式,Windows下生成的zip文件中的编码是GBK/GB2312等,因此,导致这些zip文件在Linux下解压时出现乱码问题,因为Linux下的默认编码是UTF8。Python方案这个方案很简单,因为如果你是*nix系统,那么python环境很有可能已经装好了。如果没有安装的话,可以到下面地址下载对应的安装包https://wiki.python.org/moin/BeginnersGuide/Downloa然后,创建python脚本文件myunzip.py,并写入如下内容[code lang="python"#作者:Latm Ak#链接:https://www.zhihu.com/question/20523036/answer/3522592#来源:知乎#著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。#!/usr/bin/env pytho... Read More

2018LeeCode算法题解一之Valid Palindrome

原题Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases.For example"A man, a plan, a canal: Panama" is a palindrome."race a car" is not a palindrome.NoteHave you consider that the string might be empty? This is a good question to ask during an interview.For the purpose of this problem, we define empty string as valid palindrome.原题链接:https://... Read More