Ruizhi Ma's Blog

Keep Calm and Carry On

Problem 88

Merge Sorted Array

问题描述 Given two sorted integer arrays nums1 and nums2, merge nums2 into nums1 as one sorted array. Note: The number of elements initialized in nums1 and nums2 are m and n respectively. You may ass...

Problem 283

Move Zores

问题描述 Given an array nums, write a function to move all 0’s to the end of it while maintaining the relative order of the non-zero elements. Example: Input: [0,1,0,3,12] Output: [1,3,12,0,0] Note: ...

Problem 134

Gas Station

问题描述 There are N gas stations along a circular route, where the amount of gas at station i is gas[i]. You have a car with an unlimited gas tank and it costs cost[i] of gas to travel from station i...

Problem 122

Best Time to Buy and Sell StockII

问题描述 Say you have an array for which the ith element is the price of a given stock on day i. Design an algorithm to find the maximum profit. You may complete as many transactions as you like (i.e....

Problem 121

Best Time to Sell Stock

问题描述 Say you have an array for which the ith element is the price of a given stock on day i. If you were only permitted to complete at most one transaction (i.e., buy one and sell one share of the...

循环链表的实现

LoopNode类 package demo2; public class LoopNode { //节点的内容 int data; //下一个节点的索引 LoopNode nextAddress = this; public LoopNode(int data){ this.data = data; } //插入一个节点 public void af...

单链表

增加新功能(显示所有节点,删除一个节点,插入一个节点)

代码实现 Node类 package demo2; public class Node { //节点的内容 int data; //下一个节点的索引 Node nextAddress; public Node(int data){ this.data = data; } //为节点追加节点 public Node append(Node node){ ...

Problem 243

Shortest Word Distance

问题描述 Given a list of words and two words word1 and word2, return the shortest distance between these two words in the list. For example, Assume that words = [“practice”, “makes”, “perfect”, “codin...

Problem 217

Contains Duplicate

问题描述 Given an array of integers, find if the array contains any duplicates. Your function should return true if any value appears at least twice in the array, and it should return false if every e...

Problem 299

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 ...