
数字串处理
文章平均质量分 62
chuandalishuo
这个作者很懒,什么都没留下…
展开
-
7. Reverse Integer
1. Java2. Pythonclass Solution(object): def reverse(self, x): """ :type x: int :rtype: int """ flag=1 if x<0: x=x*(-1)原创 2016-03-02 16:39:52 · 187 阅读 · 0 评论 -
287. Find the Duplicate Number
Given an array nums containing n + 1 integers where each integer is between 1 and n (inclusive), prove that at least one duplicate number must exist. Assume that there is only one duplicate number,原创 2016-11-01 01:18:37 · 170 阅读 · 0 评论 -
371. Sum of Two Integers
Calculate the sum of two integers a and b, but you are not allowed to use the operator + and -.Example:Given a = 1 and b = 2, return 3.思路:a^b异或等于无进位的加法,(a&b)解法一:public class Solution {原创 2016-11-01 00:15:57 · 162 阅读 · 0 评论 -
202. Happy Number
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原创 2016-10-20 07:23:00 · 196 阅读 · 0 评论 -
171. Excel Sheet Column Number
Given a column title as appear in an Excel sheet, return its corresponding column number.For example: A -> 1 B -> 2 C -> 3 ... Z -> 26 AA -> 27 AB -> 28 public c原创 2016-10-05 09:19:11 · 191 阅读 · 0 评论 -
190. Reverse Bits
Reverse bits of a given 32 bits unsigned integer.For example, given input 43261596 (represented in binary as 00000010100101000001111010011100), return 964176192 (represented in binary as 001110010原创 2016-10-18 02:28:22 · 268 阅读 · 0 评论 -
217, 219,220. Contains Duplicate I, II, III
Given an array of integers, find if the array contains any duplicates. Your function should return true if any value appears at least twice in the array, and it should return false if every element原创 2016-10-27 01:40:41 · 302 阅读 · 0 评论 -
166. Fraction to Recurring Decimal
Given two integers representing the numerator and denominator of a fraction, return the fraction in string format.If the fractional part is repeating, enclose the repeating part in parentheses.原创 2016-09-30 05:15:58 · 157 阅读 · 0 评论 -
189. Rotate Array
Rotate an array of n elements to the right by k steps.For example, with n = 7 and k = 3, the array [1,2,3,4,5,6,7] is rotated to [5,6,7,1,2,3,4].Try to come up as many solutions as you can,原创 2016-10-14 09:11:08 · 179 阅读 · 0 评论 -
187. Repeated DNA Sequences
All DNA is composed of a series of nucleotides abbreviated as A, C, G, and T, for example: "ACGAATTCCG". When studying DNA, it is sometimes useful to identify repeated sequences within the DNA.Wri原创 2016-10-12 07:26:07 · 146 阅读 · 0 评论 -
179. Largest Number
Given a list of non negative integers, arrange them such that they form the largest number.For example, given [3, 30, 34, 5, 9], the largest formed number is 9534330.Note: The result may be ve原创 2016-10-12 06:21:30 · 173 阅读 · 0 评论 -
27. Remove Element [easy]
题目Given an array and a value, remove all instances of that value in place and return the new length.Do not allocate extra space for another array, you must do this in place with constant memor原创 2016-06-03 09:36:33 · 183 阅读 · 0 评论 -
26. Remove Duplicates from Sorted Array [easy]
题目:Given a sorted array, remove the duplicates in place such that each element appear only once and return the new length.Do not allocate extra space for another array, you must do this in pla原创 2016-06-03 09:25:36 · 207 阅读 · 0 评论 -
13. Roman to Integer
Javapublic class Solution { public int romanToInt(String s) { int res=0; if(s.length()==0) return 0; int[] radix = {1000, 500, 100, 50, 10, 5, 1}; char[] symbol原创 2016-03-14 10:18:23 · 175 阅读 · 0 评论 -
12. Integer to Roman
Javapublic class Solution { public String intToRoman(int num) { int[] radix = {1000, 900, 500, 400, 100, 90,50, 40, 10, 9, 5, 4, 1}; String[] symbol = {"M", "CM", "D", "CD", "C",原创 2016-03-14 07:43:23 · 212 阅读 · 0 评论 -
9. Palindrome Number
1. Javapublic class Solution { public boolean isPalindrome(int x) { if(x<0) return false; return x==reverse(x); } public int reverse(int x) { long sum=0;原创 2016-03-08 04:35:26 · 251 阅读 · 0 评论 -
209. Minimum Size Subarray Sum
Given an array of n positive integers and a positive integer s, find the minimal length of a subarray of which the sum ≥ s. If there isn't one, return 0 instead.For example, given the array [2,3原创 2016-10-22 02:25:28 · 179 阅读 · 0 评论