- 博客(16)
- 收藏
- 关注
原创 405. Convert a Number to Hexadecimal#2
Solution#1 Problem#1 试着用位操作去解决,而不是通过触发
2017-01-08 22:02:28 152
原创 415. Add Strings#1(Done)
Solution#1public class Solution { public String addStrings(String num1, String num2) { if (num1.equals("0")) return num2; if (num2.equals("0")) return num1;
2017-01-08 21:22:54 162
原创 401. Binary Watch#1(Done)
Solution#1public class Solution { public List<String> readBinaryWatch(int num) { if (num < 0 || num > 10) throw new IllegalArgumentException("the argument for readBinaryWatch is
2017-01-08 16:28:58 269
原创 387. First Unique Character in a String
题目摘要 给定一个字符串,返回第一个没有重复的字母的下标,如果不存在,返回-1。假设字符串中只含有小写字母。
2017-01-08 14:22:38 141
原创 447. Number of Boomerangs
题目摘要 给定平面上的n个点,一个”boomerangs”值三个点(i, j, k),i到j的距离和i到k的距离相等,找到boomerangs的数量。解法 遍历二元数组n,每次循环,将改点与其它点的<距离, 该距离点数量>存到一个hashmap里,每次循环boomerangs的数量为map的每个value * (value - 1)相加public class Solution { pu
2017-01-06 21:12:35 148
原创 387. First Unique Character in a String#2(Done)
Solution#1public class Solution { public int firstUniqChar(String s) { if (s == null || s.length() == 0) return -1; int[] position = new int[26]; for (int i = 0
2017-01-03 22:08:28 181
原创 447. Number of Boomerangs#2(Done)
Solution#1Problem#1 map的用法,getOrDefault(key, default),遍历方法
2017-01-03 20:21:58 142
原创 404. Sum of Left Leaves#2(Done)
Solution#2/** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) { val = x; } * } */ // 递归 public cl
2017-01-03 16:27:24 132
原创 383. Ransom Note#1(Done)
Solution#1public class Solution { public boolean canConstruct(String ransomNote, String magazine) { int[] table = new int[26]; // char[] mc = magezine.toCharArray(); for (ch
2017-01-03 11:59:28 308
原创 448. Find All Numbers Disappeared in an Array
题目摘要 给定一个整形数组,其中1≤a[i]≤n(n为数组长度),一些元素出现两次一些元素只出现一次,找到1~n中所有没有出现的元素。请用O(n)的时间复杂度,并且不使用额外的空间。
2017-01-03 11:23:42 197
原创 453. Minimum Moves to Equal Array Elements
题目摘要 给定一个非空n长数组,找出使数组所有元素相等的最小步数,每一步操作为将数组中n-1个元素加一。解法 设tmp = nums[0],遍历数组,如果nums[i] > tmp,则步数result += nums[i] - tmp,如果nums[i] < tmp,则步数result += (tmp - nums[i]) * i; tmp = nums[i];public class Solu
2017-01-01 18:31:48 198
原创 453. Minimum Moves to Equal Array Elements#1(Done)
Solution#1public class Solution { public int minMoves(int[] nums) { int result = 0; int tmp = nums[0]; for (int i = 0; i < nums.length; i++) { if (tmp < nums[i])
2017-01-01 18:24:53 146
原创 448. Find All Numbers Disappeared in an Array#2(Done)
Solution#1public class Solution { public List<Integer> findDisappearedNumbers(int[] nums) { List<Integer> list = new ArrayList<>(); if (nums == null || nums.length == 0) return list
2017-01-01 17:44:20 136
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人