【LeetCode OJ 136】Single Number】的更多相关文章

题目链接:https://leetcode.com/problems/single-number/ 题目:Given an array of integers, every element appears twice except for one. Find that single one. Note: Your algorithm should have a linear runtime complexity. Could you implement it without using extr…
题目链接:https://leetcode.com/problems/missing-number/ 题目:Given an array containing n distinct numbers taken from 0, 1, 2, ..., n, find the one that is missing from the array. For example, Given nums = [0, 1, 3] return 2. Note: Your algorithm should run…
LeetCode第9题 Determine whether an integer is a palindrome. An integer is a palindrome when it reads the same backward as forward. Example 1: Input: 121 Output: true Example 2: Input: -121 Output: false Explanation: From left to right, it reads -121. F…
问题描述:给出一个整数数组,除了一个元素外,其他每个元素都出现了2次,找出只出现1次的元素. int singleNumber(vector<int>& nums); 分析:比较自然的想法是用一个容器来进行插入.查找.删除操作.遍历nums,先查找容器中是否包含该元素,是则插入,否则删除.最后容器中只剩下只出现1次的元素. 解法: int singleNumber(vector<int>& nums) { int i = 0; unordered_set<in…
题目链接:https://leetcode.com/problems/3sum-closest/ 题目:Given an array S of n integers, find three integers in S such that the sum is closest to a given number, target. Return the sum of the three integers. You may assume that each input would have exact…
题目 Given an array of integers, every element appears twice except for one. Find that single one. Note: Your algorithm should have a linear runtime complexity. Could you implement it without using extra memory? 分析 给定一个序列 找出只出现一次的元素,其它元素均出现2次: 要求线性时间,不…
题目链接:https://leetcode.com/problems/implement-queue-using-stacks/ 题目:Implement the following operations of a queue using stacks. push(x) -- Push element x to the back of queue. pop() -- Removes the element from in front of queue. peek() -- Get the fro…
题目链接:https://leetcode.com/problems/search-for-a-range/ 题目:Given a sorted array of integers, find the starting and ending position of a given target value. Your algorithm's runtime complexity must be in the order of O(log n). If the target is not foun…
题目链接:https://leetcode.com/problems/longest-common-prefix/ 题目:Write a function to find the longest common prefix string amongst an array of strings. 解题思路:寻找字符串数组的最长公共前缀,将数组的第一个元素作为默认公共前缀.依次与后面的元素进行比較.取其公共部分,比較结束后.剩下的就是该字符串数组的最长公共前缀.演示样例代码例如以下: public…
[leetcode 字符串处理]Compare Version Numbers @author:wepon @blog:http://blog.csdn.net/u012162613 1.题目 Compare two version numbers version1 and version1. If version1 > version2 return 1, if version1 < version2 return -1, otherwise return 0. You may assume…