自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+

sadjuno的博客

一只埋头进步的小菜鸟

  • 博客(46)
  • 收藏
  • 关注

原创 [206]Reverse Linked List

【题目描述】Reverse a singly linked list.【思路】新建一个链表,每从旧链表中得到一个节点就放到这个链表的最前面。【代码】/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *ne

2015-09-28 21:16:43 218

原创 [205]Isomorphic Strings

【题目描述】Given two strings s and t, determine if they are isomorphic.Two strings are isomorphic if the characters in s can be replaced to get t.All occurrences of a character must be replac

2015-09-28 20:42:52 180

原创 [204]Count Primes

【题目描述】Description:Count the number of prime numbers less than a non-negative number, n.【思路】很经典的题目,计算n之内有多少个素数,不过题目有时间要求,一开始用原始做法直接TLE了,现在代码中判断素数的方法是最为经典的,要牢牢记住。【代码】class Solution {p

2015-09-28 17:22:44 213

原创 [203]Remove Linked List Elements

【题目描述】Remove all elements from a linked list of integers that have value val.ExampleGiven: 1 --> 2 --> 6 --> 3 --> 4 --> 5 --> 6, val = 6Return: 1 --> 2 --> 3 --> 4 --> 5【思路】无【代码】

2015-09-28 16:45:31 185

原创 [202]Happy Number

【题目描述】Write an algorithm to determine if a number is "happy".A happy number is a number defined by the following process: Starting with any positive integer, replace the number by the sum of

2015-09-28 10:13:22 218

原创 [198]House Robber

【题目描述】You are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed, the only constraint stopping you from robbing each of them is that ad

2015-09-27 21:02:59 201

原创 [191]Number of 1 Bits

【题目描述】Write a function that takes an unsigned integer and returns the number of ’1' bits it has (also known as the Hamming weight).For example, the 32-bit integer ’11' has binary represent

2015-09-27 20:28:54 197

原创 Reverse Bits

【题目描述】Reverse bits of a given 32 bits unsigned integer.For example, given input 43261596 (represented in binary as 00000010100101000001111010011100), return 964176192 (represented in binary

2015-09-27 19:54:22 248

转载 STL学习之vector容器

一、创建vector对象1、vector ival; 创建一个空的整形的容器对象ival。2、vector ival(n);创建一个具有n个元素的整形vector对象。3、vector ival(n,value);创建一个具有n个元素的vector对象,每个对象初始值为value。4、vector ival1(ival2);通过拷贝一个vector对象的各个元素值,

2015-09-25 20:14:32 204

原创 Rotate Array

【题目描述】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].【思路】1.每次都是把第n-1个数插入到最前面,最后再将这个vec

2015-09-25 17:12:55 176

原创 Factorial Trailing Zeroes

【题目描述】Given an integer n, return the number of trailing zeroes in n!.Note: Your solution should be in logarithmic time complexity.【思路】看n的阶乘里有多少个0,只要看1~n中有多少个2和5就可以了,又因为2肯定比5多,所以只要看5有多少个就

2015-09-24 21:10:27 179

原创 Excel Sheet Column Number

【题目描述】Related to question Excel Sheet Column TitleGiven a column title as appear in an Excel sheet, return its corresponding column number.For example: A -> 1 B -> 2 C -> 3

2015-09-24 20:57:53 172

原创 Majority Element

【题目描述】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 the array is non-empty and the major

2015-09-24 20:30:52 169

原创 Excel Sheet Column Title

【题目描述】Given a positive integer, return its corresponding column title as appear in an Excel sheet.For example: 1 -> A 2 -> B 3 -> C ... 26 -> Z 27 -> AA 28 -> AB

2015-09-24 20:03:53 144

原创 Intersection of Two Linked Lists

【题目描述】Write a program to find the node at which the intersection of two singly linked lists begins.For example, the following two linked lists:A: a1 → a2 ↘

2015-09-23 20:35:42 146

原创 Min Stack

【题目描述】Design a stack that supports push, pop, top, and retrieving the minimum element in constant time.push(x) -- Push element x onto stack.pop() -- Removes the element on top of the stack.t

2015-09-23 10:26:31 196

转载 STL学习之transform函数

transform函数的作用是:将某操作应用于指定范围的每个元素。transform函数有两个重载版本:transform(first,last,result,op);//first是容器的首迭代器,last为容器的末迭代器,result为存放结果的容器,op为要进行操作的一元函数对象或sturct、class。transform(first1,last1,first2,result,

2015-09-22 22:35:22 850

原创 Valid Palindrome

【题目描述】Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases.For example,"A man, a plan, a canal: Panama" is a palindrome."race a ca

2015-09-22 22:28:35 199

原创 Pascal's Triangle II

【题目描述】Given an index k, return the kth row of the Pascal's triangle.For example, given k = 3,Return [1,3,3,1].【思路】和Pascal's Triangle的第二种思路一样,只是这次输出第rowIndex行的值而不是输出所有的。【代码】class

2015-09-22 21:16:02 154

原创 Pascal's Triangle

【题目描述】Given numRows, generate the first numRows of Pascal's triangle.For example, given numRows = 5,Return[ [1], [1,1], [1,2,1], [1,3,3,1], [1,4,6,4,1]]【思路】有两种思路:思路

2015-09-22 21:00:24 143

原创 Path Sum

【题目描述】Given a binary tree and a sum, determine if the tree has a root-to-leaf path such that adding up all the values along the path equals the given sum.For example:Given the below binary t

2015-09-21 21:35:50 166

转载 STL之pair对象

Utilities  由短小精干的类和函数构成,执行最一般性的工作。 这些工具包括: general types 一些重要的C函数 numeric limitsPairs C++标准程序库中凡是“必须返回两个值”的函数, 也都会利用pair对象 classpair可以将两个值视为一个单元。容器类别map和multimap就是使用pairs来管理其健值/实

2015-09-21 11:28:52 326

原创 Minimum Depth of Binary Tree

【题目描述】Given a binary tree, find its minimum depth.The minimum depth is the number of nodes along the shortest path from the root node down to the nearest leaf node.【思路】一般这样的题目既可以用递归的方法也可

2015-09-20 22:13:33 197

原创 Balanced Binary Tree

【题目描述】Given a binary tree, determine if it is height-balanced.For this problem, a height-balanced binary tree is defined as a binary tree in which the depth of the two subtrees of every node

2015-09-20 21:14:22 154

原创 Binary Tree Level Order Traversal II

【题目描述】Given a binary tree, return the bottom-up level order traversal of its nodes' values. (ie, from left to right, level by level from leaf to root).For example:Given binary tree {3,9,20

2015-09-20 20:06:51 159

原创 Maximum Depth of Binary Tree

【题目描述】Given a binary tree, find its maximum depth.The maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node.【思路】树的递归题【代码】/**

2015-09-19 11:24:02 182

原创 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 / \

2015-09-18 20:34:50 160

原创 Symmetric Tree

【题目描述】Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center).For example, this binary tree is symmetric: 1 / \ 2 2 / \ / \3 4 4 3

2015-09-16 10:28:50 171

原创 Same Tree

【题目描述】Given 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.【思路】一开始以

2015-09-15 21:52:41 165

原创 Remove Duplicates from Sorted List

【题目描述】Given a sorted linked list, delete all duplicates such that each element appear only once.【思路】链表题。没什么技术含量,就不多讲了。【代码】/** * Definition for singly-linked list. * struct ListNode { *

2015-09-15 21:00:33 200

原创 20115.9.14

每次上leetcode都会出现ac了一道题之后就再也上不去网站了,好坑爹=。=

2015-09-14 16:07:38 162

原创 Climbing Stairs

【题目描述】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?【思路】数学题。找到规律即可。当

2015-09-14 15:52:11 231

原创 Add Binary

【题目描述】Given two binary strings, return their sum (also a binary string).For example,a = "11"b = "1"Return "100".【思路】依然是模拟题,我的思路是将长度短的那个字符串前面补零和另一个的长度相等,然后模仿多位加法计算。【代码】class Sol

2015-09-13 20:14:57 206

原创 Plus One

【题目描述】Given a non-negative number represented as an array of digits, plus one to the number.The digits are stored such that the most significant digit is at the head of the list.【思路】纯模拟题

2015-09-13 17:28:08 200

原创 Count and Say

【题目描述】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

2015-09-12 21:35:35 160

原创 Implement strStr()

【题目描述】Implement strStr().Returns the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack.【思路】暴力求解,复杂度o(n*m),速度还蛮快的,4ms【代码】class Solution {pu

2015-09-12 11:34:20 162

原创 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

2015-09-12 10:33:57 240

原创 Remove Duplicates from Sorted Array

【题目描述】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, you must do this i

2015-09-12 10:32:11 185

原创 Merge Two Sorted Lists

【题目描述】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.【思路】经典链表题,注意p,q的初始化。【代码】/** * Definiti

2015-09-11 20:33:48 224

原创 Valid Parentheses

【题目描述】Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid.The brackets must close in the correct order, "()" and "()[]{}" 

2015-09-11 18:36:44 182

空空如也

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除