Problem: Reverse digits of an integer. Example1: x = 123, return 321Example2: x = -123, return -321 终于什么都没参考就一次Accept了.可能是这题比较简单,同时自己也进步了一点点,leetcode就是这样给我们增加信心的吧. 我是这样想的,利用除10和模10两个操作,将每个数字分离在vec中,然后相应的乘以10的倍数输出就行.如果这个数在-10与10之间直接返回就好. 代码如下: class S…
Reverse Integer Reverse digits of an integer. Example1: x = 123, return 321 Example2: x = -123, return -321 time=272ms accepted public class Solution { public int reverse(int x) { long recv=0; int mod=0; int xabs=Math.abs(x); while(xabs>0){ mod=xabs%…
==数组 Medium== 40.(162)Find Peak Element JAVA //斜率思想,二分法 class Solution { public int findPeakElement(int[] nums) { int l=0,r=nums.length-1; while(l<r){ int mid = (r+l)/2; if(nums[mid]>nums[mid+1]) r = mid; else l = mid+1; } return l; } } 41.(731)My C…
Reverse digits of an integer. Example1: x = 123, return 321Example2: x = -123, return -321 Have you thought about this? Here are some good questions to ask before coding. Bonus points for you if you have already thought through this! If the integer's…
Given an integer, return its base 7 string representation. Example 1: Input: 100 Output: "202" Example 2: Input: -7 Output: "-10" Note: The input will be in range of [-1e7, 1e7]. 这道题给了我们一个数,让我们转为七进制的数,而且这个可正可负.那么我们想如果给一个十进制的100,怎么转为七进制…