随笔分类 - 【103】leetcode题解
摘要:You have a total of n coins that you want to form in a staircase shape, where every k-th row must have exactly k coins. Given n, find the total number
阅读全文
摘要:Given two non-negative numbers num1 and num2 represented as string, return the sum of num1 and num2. Note: 我的第一个想法就是选好两个字符串,然后模拟加法进位,然后用一个字符串接着,同时记住进位
阅读全文
摘要:Given a sorted linked list, delete all duplicates such that each element appear only once. For example, Given 1->1->2, return 1->2. Given 1->1->2->3->
阅读全文
摘要:Given a linked list, swap every two adjacent nodes and return its head. For example, Given 1->2->3->4, you should return the list as 2->1->4->3. Your
阅读全文
摘要:Merge two sorted linked lists and return it as a new list. The new list should be made by splicing together the nodes of the first two lists. Subscrib
阅读全文
摘要:Given a string, find the first non-repeating character in it and return it's index. If it doesn't exist, return -1. Examples: 除了两次for循环,暂时没有想到N时间复杂度的解
阅读全文
摘要:Given a string which consists of lowercase or uppercase letters, find the length of the longest palindromes that can be built with those letters. This
阅读全文
摘要:已知两个字符串,然后比较一个字符串是否来自另一个字符串,没有顺序要求。 简单题,用一个数组保存前一个字符串的每一个字符出现的次数,然后循环后一个字符串去检查,如果次数不够了,那么就返回false
阅读全文
摘要:Given an array of integers, every element appears twice except for one. Find that single one. Note: Your algorithm should have a linear runtime comple
阅读全文
摘要:Given an integer (signed 32 bits), write a function to check whether it is a power of 4. Example: Given num = 16, return true. Given num = 5, return f
阅读全文
摘要:Find the sum of all left leaves in a given binary tree. Example: 题目给出的意思很简单。就只是单纯的树的遍历而已。意思是计算出所有左叶子节点的值的和。 我采用递归的方式表示我的遍历顺序,其实主要的是要理解题目的意思,这里的叶子是最后的叶
阅读全文
摘要:You are climbing a stair case. It takes n steps to reach to the top. Each time you can either climb 1 or 2 steps. In how many distinct ways can you cl
阅读全文
摘要:我这道题目真的是划水的,因为弄了很长时间发现,我可能对于位操作不是特别喜欢吧。 确实为了最求速度,位操作确实快一些。 单独从题目意思来说,用别的方式实现加法,我觉得吧,真的有点醉了。。。就这样。 下面给出大神的位操作总结报告,积累一下经验吧。 https://discuss.leetcode.com
阅读全文
摘要:Write an algorithm to determine if a number is "happy". 写出一个算法确定一个数是不是快乐数。 A happy number is a number defined by the following process: Starting with
阅读全文
摘要:Given two strings s and t which consist of only lowercase letters. 给出两个字符串,s和t,都是只有小写字母组成的。 String t is generated by random shuffling string s and the
阅读全文
摘要:public class Solution { public boolean isUgly(int num) { if(num == 1) return true; if(num == 0) return false; if(num%2 == 0) return isUgly(num/2); if(
阅读全文