lintcode:组成最大的数】的更多相关文章

题目1 落单的数 给出2*n + 1 个的数字,除其中一个数字之外其他每个数字均出现两次,找到这个数字. 链接:http://www.lintcode.com/zh-cn/problem/single-number/ 样例 给出 [1,2,2,1,3,4,3],返回 4 挑战 一次遍历,常数级的额外空间复杂度 解决方案 方法1思路:将所有的数转换成二进制,因为是int类型,共32位.申请常数级(32位)的额外空间,然后每个数对应的位相加,最后对应位上的和模2.最后的结果就是单个数对应的二进制数.…
题目描述: 我的代码: public class Solution { /* * @param num: a positive number * @return: true if it's a palindrome or false */ public boolean isPalindrome(int num) { // write your code here int i=0,count=0; int n = num; while(n != 0) { n/=10; count++; } int…
Given an array of integers, find two numbers such that they add up to a specific target number. The function twoSum should return indices of the two numbers such that they add up to the target, where index1 must be less than index2. Please note that…
Write an algorithm to determine if a number is happy. A happy number is a number defined by the following process: Starting with any positive integer, replace the number by the sum of the squares of its digits, and repeat the process until the number…
Write a program to check whether a given number is an ugly number`. Ugly numbers are positive numbers whose prime factors only include 2, 3, 5. For example, 6, 8 are ugly while 14 is not ugly since it includes another prime factor 7. Notice Note that…
最大数 给出一组非负整数,重新排列他们的顺序把他们组成一个最大的整数. 注意事项 最后的结果可能很大,所以我们返回一个字符串来代替这个整数. 样例 给出 [1, 20, 23, 4, 8],返回组合最大的整数应为8423201. 解题 本质上是一种排序,但是排序规则如何定义? 对于20 23 可以组成2023 和2320 显然2320更大应该排在前面 对于5 51 可以组成551 和 515 显然551更大应该排在前面 所以在比较两个数大小的规则应该将两个数链接起来后再比较大小 对于left.r…
class Solution { public: /** * @param nums: a vector of integers * @return: an integer */ int findMissing(vector<int> &nums) { // write your code here int n = nums.size(); ; ; i <= n; i++) number ^= i; ; i < n; i++) number ^= nums[i]; retu…
题目链接:http://www.lintcode.com/zh-cn/problem/two-sum/ 给一个整数数组,找到两个数使得他们的和等于一个给定的数target. 备份一份,然后排序.搞两个指针分别从左从右开始扫描,每次判断这两个数相加是不是符合题意,如果小了,那就把左边的指针向右移,同理右指针.然后在备份的数组里找到位置. class Solution: """ @param numbers : An array of Integer @param target…
LintCode有大部分题目来自LeetCode,但LeetCode比较卡,下面以LintCode为平台,简单介绍我AC的几个题目,并由此引出一些算法基础. 1)两数之和(two-sum) 题目编号:56,链接:http://www.lintcode.com/zh-cn/problem/two-sum/ 题目描述: 给一个整数数组,找到两个数使得他们的和等于一个给定的数 target. 你需要实现的函数twoSum需要返回这两个数的下标, 并且第一个下标小于第二个下标.注意这里下标的范围是 1…
-------------------------------- 这道题好坑啊,自己说是2*n+1个数字,结果有组测试数据竟然传了个空数组进来... 经典位算法: n^n==0 n^0==n AC代码: public class Solution { /** *@param A : an integer array *return : a integer */ public int singleNumber(int[] A) { if(A.length==0) return 0; int n=A…