【LeetCode从零单排】No102 Binary Tree Level Order Traversal

题目       Given a binary tree, return the level order traversal of its nodes' values. (ie, from left to right, level by level).For example:Given binary tree {3,9,20,#,#,15,7}, 3 / \ 9 20 /...
阅读(1055) 评论(2)

【LeetCode从零单排】No100 Same Tree && No101 Symmetric Tree

题目1.same treeGiven two binary trees, write a function to check if they are equal or not.Two binary trees are considered equal if they are structurally identical and the nodes have the same value.2.sym...
阅读(967) 评论(0)

【LeetCode从零单排】No83 Remove Duplicates from Sorted List

题目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->3, return 1->2->3.代码 public static ListNode deleteD...
阅读(908) 评论(0)

【LeetCode从零单排】No88.Merge Sorted Array

题目Given two sorted integer arrays A and B, merge B into A as one sorted array.Note:You may assume that A has enough space (size that is greater or equal to m + n) to hold additional elements from B. T...
阅读(886) 评论(0)


题目          爬楼梯问题,这是一道很有趣的问题。首先看题目: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 climb to the top?这...
阅读(1441) 评论(0)


题目Given two binary strings, return their sum (also a binary string).For example,a = "11"b = "1"Return "100".代码public class Solution { public String addBinary(String a, String b) { S...
阅读(830) 评论(0)

【LeetCode从零单排】No58.Length of Last Word

题目Given a string s consists of upper/lower-case alphabets and empty space characters ' ', return the length of last word in the string.If the last word does not exist, return 0.Note: A word is defined...
阅读(885) 评论(0)


题目The count-and-say sequence is the sequence of integers beginning as follows:1, 11, 21, 1211, 111221, ...1 is read off as "one 1" or 11.11 is read off as "two 1s" or 21.21 is read off as "one 2, then...
阅读(885) 评论(0)

【LeetCode从零单排】No36 Valid Sudoku

题目      判断数独是否成立的一道题,看的是某大神的答案,写的太漂亮了。Determine if a Sudoku is valid, according to: Sudoku Puzzles - The Rules.The Sudoku board could be partially filled, where empty cells are filled with the charact...
阅读(836) 评论(0)

【LeetCode从零单排】No28 Implement strStr()

题目Implement strStr().Returns the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack.代码public class Solution { public int strStr(String haystack, String ne...
阅读(889) 评论(0)

【LeetCode从零单排】No27.Remove Element

题目    Given an array and a value, remove all instances of that value in place and return the new length.The order of elements can be changed. It doesn't matter what you leave beyond the new length.代码p...
阅读(778) 评论(0)


题目      这道题是链表的简单应用,将两个有序链表合成一个有序链表。       思路是:表一,表二各取两个对象,分别指向current和next,进行交叉比较排序。Merge two sorted linked lists and return it as a new list. The new list should be made by splicing together the nod...
阅读(916) 评论(0)

【LeetCode从零单排】No26.Remove Duplicates from Sorted Array

题目     题目要求:去除sort int数组中的重复项。     Given a sorted array, remove the duplicates in place such that each element appear only once and return the new length.Do not allocate extra space for another array,...
阅读(817) 评论(0)


题目        这是道链表的简单应用题目,删除从结尾数第n个节点。Given a linked list, remove the nth node from the end of list and return its head.For example, Given linked list: 1->2->3->4->5, and n = 2. After removing the ...
阅读(897) 评论(0)


题目            Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid.     The brackets must close in the correct order, "()" and "()[]{}"...
阅读(798) 评论(0)


题目    Write a function to find the longest common prefix string amongst an array of strings.代码public class Solution { public String longestCommonPrefix(String[] strs) { if(strs.length==0) ...
阅读(820) 评论(0)

【LeetCode从零单排】No.9 Palindrome Number

题目      这道题是迄今为止最快通过的一道题,改了两次就过了,runtime一般(中等偏下,这点不太满意)。Palindrome就是判断一个整数是否对称。Determine whether an integer is a palindrome. Do this without extra space.click to show spoilers.Some hints:Could negativ...
阅读(930) 评论(0)

【LeetCode从零单排】No.8 String to Integer (丧心病狂的一道题)

题目       题目很简单,就是写一个函数把string转换成int,但是通过率只有可怜的11%,难点是要考虑所有情况,特别是int溢出边界,反正我是写了2个小时还没解决,先放到这,有空接着搞,现在应该还有最后一个bug。Implement atoi to convert a string to an integer.Hint: Carefully consider all possible i...
阅读(953) 评论(0)

【LeetCode从零单排】No.7 Reverse Integer

前话      今天开始励志刷一下leetcode上面的题目(还好这个网站没被TG和谐)。从easy的开始,数一下差不多有40道,争取两个月搞定。题目       没想到做的第一道题目,虽然看似简单,却费了很大周折。题目如下:Reverse digits of an integer.Example1: x = 123, return 321Example2: x = -123, return -3...
阅读(1040) 评论(2)


1.背景     追随着buptwusuopu大神的脚步,最近在研习动态规划。动态规划应该叫一种解决问题的思想,记得又一次去某公司面试就被问到了这个。       多于动态规划的理解,大致是这样的,从空集合开始,每增加一个元素就求它的最优解,直到所有元素加进来,就得到了总的最优解。           比较典型的应用就是背包问题,有一个重量一定的包,有若干件物品,他们各自有不同的重量和价值,怎样背...
阅读(3887) 评论(1)
248条 共13页首页 上一页 1 2 3 4 5 ... 下一页 尾页



    • 访问:639609次
    • 积分:9077
    • 等级:
    • 排名:千里之外
    • 原创:215篇
    • 转载:33篇
    • 译文:0篇
    • 评论:417条