- 浏览: 88920 次
最新评论
-
hcx2013:
mircle 写道Given nums = [1, 2, 1, ...
Single Number III -
mircle:
Given nums = [1, 2, 1, 3, 2, 5, ...
Single Number III -
hcx2013:
恩,可以,代码更简洁
空格替换 -
QuarterLifeForJava:
这样可以吗?
public static void main( ...
空格替换 -
hcx2013:
这个2是指多出2位,按你的理解可以这么改:int len = ...
空格替换
文章列表
Given a binary tree, determine if it is a valid binary search tree (BST).
Assume a BST is defined as follows:
The left subtree of a node contains only nodes with keys less than the node's key.
The right subtree of a node contains only nodes with keys greater than the node's key.
Both the left a ...
Interleaving String
- 博客分类:
- leetcode
Given s1, s2, s3, find whether s3 is formed by the interleaving of s1 and s2.
For example,Given:s1 = "aabcc",s2 = "dbbca",
When s3 = "aadbbcbcac", return true.When s3 = "aadbbbaccc", return false.
public class Solution {
public boolean isInterleave( ...
题目描述
请编写一个方法,将字符串中的空格全部替换为“%20”。假定该字符串有足够的空间存放新增的字符,并且知道字符串的真实长度(小于等于1000),同时保证字符串由大小写的英文字母组成。
给定一个string iniString 为原始的串,以及串的长度 int len, 返回替换后的string。
测试样例:
"Mr John Smith”,13
返回:"Mr%20John%20Smith"
”Hello World”,12
返回:”Hello%20%20World”
import java.util.*;
pub ...
描述
给出一个名字,该名字有26个字符串组成,定义这个字符串的“漂亮度”是其所有字母“漂亮度”的总和。每个字母都有一个“漂亮度”,范围在1到26之间。没有任何两个字母拥有相同的“漂亮度”。字母忽略大小写。给出多个名字,计算每个名字最大可能的“漂亮度”。
知识点
字符串
运行时间限制
0M
内存限制
字符串最后一个单词的长度
- 博客分类:
- 华为oj
描述
计算字符串最后一个单词的长度,单词以空格隔开。
知识点
字符串,循环
运行时间限制
0M
内存限制
0
输入
一行字符串,长度小于128。
描述
计算最少出列多少位同学,使得剩下的同学排成合唱队形
说明:
N位同学站成一排,音乐老师要请其中的(N-K)位同学出列,使得剩下的K位同学排成合唱队形。 合唱队形是指这样的一种队形:设K位同学从左到右依次编号为1,2…,K,他们的身高分别为T1,T2,…,TK, 则他们的身高满足存在i(1<=i<=K)使得Ti<T2<......<Ti-1<Ti>Ti+1>......>TK。 你的任务是,已知所有N位同学的身高,计算最少需要几位同学出列,可以使得剩下的同学排成合唱队形。
知识点
循 ...
描述
Lily上课时使用字母数字图片教小朋友们学习英语单词,每次都需要把这些图片按照大小(ASCII码值从小到大)排列收好。请大家给Lily帮忙,通过C语言解决。
知识点
字符串
运行时间限制
0M
内存限制
0
输入
Given n, how many structurally unique BST's (binary search trees) that store values 1...n?
For example,Given n = 3, there are a total of 5 unique BST's.
1 3 3 2 1
\ / / / \ \
3 2 1 1 3 2
/ / \ \ ...
Given n, generate all structurally unique BST's (binary search trees) that store values 1...n.
For example,Given n = 3, your program should return all 5 unique BST's shown below.
1 3 3 2 1
\ / / / \ \
3 2 1 1 3 2
/ / ...
Given a binary tree, return the inorder traversal of its nodes' values.
For example:Given binary tree {1,#,2,3},
1
\
2
/
3
return [1,3,2].
/**
* Definition for a binary tree node.
* public class TreeNode {
* int val;
* TreeNode left;
* TreeNod ...
Restore IP Addresses
- 博客分类:
- leetcode
Given a string containing only digits, restore it by returning all possible valid IP address combinations.
For example:Given "25525511135",
return ["255.255.11.135", "255.255.111.35"]. (Order does not matter)
public class Solution {
public List<String> ...
Reverse a linked list from position m to n. Do it in-place and in one-pass.
For example:Given 1->2->3->4->5->NULL, m = 2 and n = 4,
return 1->4->3->2->5->NULL.
Note:Given m, n satisfy the following condition:1 ≤ m ≤ n ≤ length of list.
/**
* Definition for sing ...
Reverse Linked List
- 博客分类:
- leetcode
Reverse a singly linked list.
/**
* Definition for singly-linked list.
* public class ListNode {
* int val;
* ListNode next;
* ListNode(int x) { val = x; }
* }
*/
public class Solution {
public ListNode reverseList(ListNode head) {
if (head==null || head. ...
Decode Ways
- 博客分类:
- leetcode
A message containing letters from A-Z is being encoded to numbers using the following mapping:
'A' -> 1
'B' -> 2
...
'Z' -> 26
Given an encoded message containing digits, determine the total number of ways to decode it.
For example,Given encoded message "12", it could be d ...
Subsets II
- 博客分类:
- leetcode
Given a collection of integers that might contain duplicates, nums, return all possible subsets.
Note:
Elements in a subset must be in non-descending order.
The solution set must not contain duplicate subsets.
For example,If nums = [1,2,2], a solution is:
[
[2],
[1],
[1,2,2],
[ ...