Ruizhi Ma's Blog

Keep Calm and Carry On

Problem 11

Container With Most Water

问题描述 https://leetcode.com/problems/container-with-most-water/ 解决思路 遇到这种涉及比较的,可以使用DP(后期再用DP实现),另一种思路就是使用双指针,不断计算amount,然后比较替换,得到结果。 问题解惑 后面因为方法countAmount方法没有被新创建的对象直接调用,所以直接return要加this,表明是当前类调用了...

Problem 7

Reverse Integer

问题描述 Given a 32-bit signed integer, reverse digits of an integer. Example 1: Input: 123 Output: 321 Example 2: Input: -123 Output: -321 Example 3: Input: 120 Output: 21 Note: Assume we are deal...

Problem 6

ZigZag Coversion

问题描述 https://leetcode.com/problems/zigzag-conversion/ 解决思路 就不讲了,感觉没什么借鉴意义这个题。有兴趣去youtube看篮子王的讲解吧。 代码 class Solution { public String convert(String s, int numRows) { char[] c = s.toCha...

Problem 5

Longest Palindromic Substring

问题描述 Given a string s, find the longest palindromic substring in s. You may assume that the maximum length of s is 1000. Example 1: Input: “babad” Output: “bab” Note: “aba” is also a valid answer...

Problem 3

Longest SubString Without Repeating Characters

问题描述 Given a string, find the length of the longest substring without repeating characters. Example 1: Input: “abcabcbb” Output: 3 Explanation: The answer is “abc”, with the length of 3. Exampl...

Problem 2

Add Two Numbers

问题描述 You are given two non-empty linked lists representing two non-negative integers. The digits are stored in reverse order and each of their nodes contain a single digit. Add the two numbers and ...

Problem 1

Two Sum

问题描述 Given an array of integers, return indices of the two numbers such that they add up to a specific target. You may assume that each input would have exactly one solution, and you may not use t...

Collections工具类

内部方法的使用

TestCollections类 package cn.sxt.collection; import java.util.ArrayList; import java.util.Collections; import java.util.List; public class TestCollections { public static void main(String[] arg...

Iterator的使用

用迭代器迭代Collection

TestIterator类 package cn.sxt.collection; import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; import java.util.List; import java.util.Map; imp...

TreeSet

TreeSet基本用法,重写Comparable接口

TestTreeSet类 package cn.sxt.collection; /* * 测试TreeSet的使用 * 测试Comparable接口 */ import java.util.Set; import java.util.TreeSet; public class TestTreeSet { public static void main(String[] args...