自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(10)
  • 收藏
  • 关注

原创 LeetCode 之 Compare Version Numbers

Compare two version numbers version1 and version2. If version1 > version2 return 1, if version1 version2 return -1, otherwise return 0. You may assume that the version strings are non-empty and co

2015-12-20 18:34:11 353

原创 LeetCode 之 Implement strStr()

Implement strStr(). Returns the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack. 首先要搞懂strStr()是啥,strStr()是判断一个字符串是否为另一个字符串的子串。最简单的算法是遍历(m-n)*n次,代码如下:

2015-12-07 19:50:52 273

原创 LeetCode 之 Reverse Integer

Reverse digits of an integer. Example1: x = 123, return 321 Example2: x = -123, return -321 从低到高位,对每个数字乘以翻转后的权值,在求和就行了,代码如下: class Solution { public: int reverse(int x) { long ans

2015-12-06 21:21:11 240

原创 LeetCode 之 Binary Tree Paths

Given a binary tree, return all root-to-leaf paths. For example, given the following binary tree: 1 / \ 2 3 \ 5 All root-to-leaf paths are: ["1->2->5", "1->3"] 又是较

2015-12-06 15:55:21 379

原创 LeetCode 之 Palindrome Linked List

Given a singly linked list, determine if it is a palindrome. Follow up: Could you do it in O(n) time and O(1) space? 方法一: 反序存一个新的链,在遍历两个链,进行比较,代码如下: bool isPalindrome(ListNode* head) {

2015-12-05 22:06:19 229

原创 LeetCode 之 Bulls and Cows

You are playing the following Bulls and Cows game with your friend: You write down a number and ask your friend to guess what the number is. Each time your friend makes a guess, you provide a hint t

2015-12-05 20:35:31 225

原创 LeetCode 之 Add Binary

Given two binary strings, return their sum (also a binary string). For example, a = "11" b = "1" Return "100". 这道题并不复杂,需要注意的是要从后往前遍历a,b求和,同时要有一个进位项,对各种情况都要分析到: string addBinary(string a, str

2015-12-04 20:51:55 216

原创 LeetCode 之 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 read off as 

2015-12-04 10:41:45 214

原创 LeetCode 之 Remove Linked List Elements

Remove all elements from a linked list of integers that have value val. Example Given: 1 --> 2 --> 6 --> 3 --> 4 --> 5 --> 6, val = 6 Return: 1 --> 2 --> 3 --> 4 --> 5 简单的链表操作: /** * Definit

2015-12-03 22:52:45 281

原创 LeetCode 之 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 replaced with anot

2015-12-02 19:14:54 207

空空如也

空空如也

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

TA关注的人

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