摘要:
题目链接:把数组排成最小的数 思路:对数组进行排序,假设要{x, y}组成最小数,那么通过比较"xy"和"yx"的大小,可以得到最小值,对整个数组按这种比较大小方式进行排序,最好得到的数组就是最小数。(证明见评论讲解) 代码: class Solution { public String minNu 阅读全文
摘要:
题目链接:数值的整数次方 思路:二分法。对幂次方进行二分,但需要考虑次方运算的特殊情况,这儿,0次方结果都为0,底数为1时结果都为1。 代码: class Solution { public double myPow(double x, int n) { if(x == 1 || x == 0) r 阅读全文
摘要:
题目链接:387.字符串的第一个唯一字符 代码: class Solution { public int firstUniqChar(String s) { int[] map = new int[26]; for(char c : s.toCharArray()){ map[c - 'a'] ++ 阅读全文
摘要:
题目链接:103.二叉树的锯齿形层序遍历 思路:双栈。 代码: /** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * Tre 阅读全文
摘要:
题目链接:746使用最小费用爬楼梯 代码: class Solution { public int minCostClimbingStairs(int[] cost) { int fir, sec; fir = sec = 0; for(int i=2; i<=cost.length; i++){ 阅读全文