ZMR小站

很高兴遇见你~


  • 首页

  • 标签

  • 分类

  • 归档

p394

发表于 2016-09-09 | 分类于 blog

LeetCode p394 Decode String 题解

1.题目:

Given an encoded string, return it’s decoded string.
The encoding rule is: k[encoded_string], where the encoded_string inside the square brackets is being repeated exactly k times. Note that k is guaranteed to be a positive integer.
You may assume that the input string is always valid; No extra white spaces, square brackets are well-formed, etc.
Furthermore, you may assume that the original data does not contain any digits and that digits are only for those repeat numbers, k. For example, there won’t be input like 3a or 2[4].
Examples:
s = “3[a]2[bc]”, return “aaabcbc”.
s = “3[a2[c]]”, return “accaccacc”.
s = “2[abc]3[cd]ef”, return “abcabccdcdcdef”.

阅读全文 »

p263

发表于 2016-09-08 | 分类于 blog

LeetCode p263 Ugly Number 题解

1.题目:

Write a program to check whether a given number is an ugly number.
Ugly numbers are positive numbers whose prime factors only include 2, 3, 5. For example, 6, 8 are ugly while 14 is not ugly since it includes another prime factor 7.
Note that 1 is typically treated as an ugly number.

阅读全文 »

p62

发表于 2016-09-08 | 分类于 blog

LeetCode p62 Unique Paths 题解

1.题目:

A robot is located at the top-left corner of a m x n grid (marked ‘Start’ in the diagram below).
The robot can only move either down or right at any point in time. The robot is trying to reach the bottom-right corner of the grid (marked ‘Finish’ in the diagram below).
How many possible unique paths are there?

阅读全文 »

p191

发表于 2016-09-08 | 分类于 blog

LeetCode p191 Number of 1 Bits 题解

1.题目:

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 representation 00000000000000000000000000001011, so the function should return 3.

阅读全文 »

p83

发表于 2016-09-08 | 分类于 blog

LeetCode p83 Remove Duplicates from Sorted List 题解

1.题目:

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.

阅读全文 »

p46

发表于 2016-09-08 | 分类于 blog

LeetCode p46 Permutations 题解

1.题目:

Given a collection of distinct numbers, return all possible permutations.
For example,
[1,2,3] have the following permutations:
[
[1,2,3],
[1,3,2],
[2,1,3],
[2,3,1],
[3,1,2],
[3,2,1]
]

阅读全文 »

p89

发表于 2016-09-07 | 分类于 blog

LeetCode p89 Gray Code 题解

1.题目:

The gray code is a binary numeral system where two successive values differ in only one bit.
Given a non-negative integer n representing the total number of bits in the code, print the sequence of gray code. A gray code sequence must begin with 0.
For example, given n = 2, return [0,1,3,2]. Its gray code sequence is:
00 - 0
01 - 1
11 - 3
10 - 2

阅读全文 »
1…202122…33
ZhangMengRou

ZhangMengRou

ZMR小站

230 日志
4 分类
14 标签
© 2019 ZhangMengRou
由 Hexo 强力驱动
|
主题 — NexT.Gemini v5.1.4