随笔分类 - LeetCode
摘要:You are given two non-empty linked lists representing two non-negative integers. The digits are stored in reverse order and each of their nodes contai
阅读全文
摘要: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
阅读全文
摘要:Given a sorted linked list, delete all duplicates such that each element appear only once. 给定一个有序数组,删除其中所有重复的元素,使每个元素只出现一次~ For example,Given 1->1->2,
阅读全文
摘要:实现针对int类型的sqrt(int x)。计算并返回x的平方根,x确定为非负整数 Implement int sqrt(int x). Compute and return the square root of x. x is guaranteed to be a non-negative int
阅读全文
摘要:给定两个二进制字符串,返回它们的和(也是一个二进制字符串) Given two binary strings, return their sum (also a binary string). For example,a = "11"b = "1"Return "100". lx223的解法 pub
阅读全文
摘要:给定一个包含大写/小写字母和空格字符' '的字符串,返回字符串中最后一个单词的长度。 如果最后一个单词不存在,返回0.(自己理解有误,认为如"a "这样即最后一个单词不存在,实际并不是,对该字符串来说,最后一个单词是a,长度为1) 注意:一个单词被定义为由不为空的字符组成的序列,即不包含' '. G
阅读全文
摘要:题目:将两个有序链表合并为一个新链表。该新链表必须是之前两个链表的节点合并而成。 Merge two sorted linked lists and return it as a new list. The new list should be made by splicing together t
阅读全文
摘要:Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid. The brackets must close in the
阅读全文
摘要:class Solution { public String longestCommonPrefix(String[] strs) { StringBuffer result = new StringBuffer(""); if (strs.length==0) return result.toSt
阅读全文
摘要:题目: The count-and-say sequence is the sequence of integers with the first five terms as following: 1 is read off as "one 1" or 11.11 is read off as "t
阅读全文
摘要:Given two binary trees, write a function to check if they are the same or not. Two binary trees are considered the same if they are structurally ident
阅读全文
摘要:Determine whether an integer is a palindrome. Do this without extra space. 确定一个整数是否回文数,不能占用额外空间。 (回文数形如121,12321,1221,5等) 大神代码cbmbbz class Solution {
阅读全文
摘要:Given a 32-bit signed integer, reverse digits of an integer. 给定一个32位有符号整数,将整数的每位反转,如下: Example 1: Example 2: Example 3: 注意:假设翻转后超出32位有符号数的范围(溢出),那么返回0
阅读全文
摘要:Given an array containing n distinct numbers taken from 0, 1, 2, ..., n, find the one that is missing from the array. 翻译:给出一个包含n个不同数字的数组,数组中元素是从0,1,2,
阅读全文
摘要: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 arr
阅读全文
摘要: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]. Not
阅读全文
摘要:Given an array of integers that is already sorted in ascending order, find two numbers such that they add up to a specific target number. The function
阅读全文
摘要:Say you have an array for which the ith element is the price of a given stock on day i. Design an algorithm to find the maximum profit. You may comple
阅读全文
摘要:问题 Given an array of size n, find the majority element. The majority element is the element that appears more than ⌊ n/2 ⌋ times. You may assume that
阅读全文
摘要:和前面119. Pascal's Triangle非常相似,不赘述,下面是代码 class Solution { public List<Integer> getRow(int row) { List<Integer> yanghui=new ArrayList<Integer>(); for (i
阅读全文