Skip to content

Instantly share code, notes, and snippets.

View bnyu's full-sized avatar
💕
hello world

xuyue bnyu

💕
hello world
View GitHub Profile
@bnyu
bnyu / linkedlist.kt
Created July 9, 2017 02:49
binyui.com上的一些记录
//kotlin
class Lnode constructor(var data: Any){
//尾节点指向尾节点自身
var next: Lnode = this
//尾部插入
fun tInsert(data: Any){
val point: Lnode = Lnode(data)
var temp: Lnode = this
while (temp.next != temp)
temp = temp.next
@bnyu
bnyu / Test.java
Last active September 27, 2017 03:07
Find odd numbers
import java.util.ArrayList;
import java.util.List;
public class Test {
private long bigOdd;
public long getBigOdd() {
return bigOdd;
}
@bnyu
bnyu / Solution.java
Last active September 27, 2017 03:08
/**
* 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 the same element twice.
*/
class Solution {
public int[] twoSum(int[] nums, int target) {
int[] sum = new int[2];
breakFor:
@bnyu
bnyu / Solution.java
Last active September 27, 2017 03:09
2. Add Two Numbers
/**
* 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 return it as a linked list.
* You may assume the two numbers do not contain any leading zero, except the number 0 itself.
*
* Definition for singly-linked list.
* public class ListNode {
* int val;
* ListNode next;
* ListNode(int x) { val = x; }
@bnyu
bnyu / Solution.java
Last active November 5, 2017 09:49
3. Longest Substring Without Repeating Characters
import java.util.HashMap;
import java.util.Map;
/**
* 3. Longest Substring Without Repeating Characters
* Given a string, find the length of the longest substring without repeating characters.
*/
// Time Limit Exceeded...
class Solution {
@bnyu
bnyu / Solution.java
Created September 25, 2017 15:12
5. Longest Palindromic Substring
class Solution {
public String longestPalindrome(String s) {
String ans;
if (!s.isEmpty()) {
char[] chars = s.toCharArray();
int length = chars.length;
int longest = 1;
ans = String.valueOf(chars[0]);
for (int i = 1; i < length; i++) {
int len = 1;
@bnyu
bnyu / Solution.java
Created September 25, 2017 16:43
6. ZigZag Conversion
class Solution {
public String convert(String s, int numRows) {
String ans;
if (!s.isEmpty() && numRows > 0) {
if (numRows == 1) {
return s;
}
int length = s.length();
char[] chars = new char[length];
int lIndex;
@bnyu
bnyu / Solution.java
Last active September 25, 2017 17:31
7. Reverse Integer
/**
* 7. Reverse Integer
* Reverse digits of an integer.
*/
class Solution {
public int reverse(int x) {
// 0x80000000 = ~0x80000000 + 1
if (x == Integer.MIN_VALUE) {
return 0;
}
@bnyu
bnyu / Solution.java
Last active September 27, 2017 03:08
9. Palindrome Number
import java.util.HashMap;
import java.util.Map;
/**
* 9. Palindrome Number
* Determine whether an integer is a palindrome. Do this without extra space.
*/
class Solution {
public boolean isPalindrome(int x) {
if (x < 0) {
@bnyu
bnyu / Solution.java
Last active September 27, 2017 03:09
10. Regular Expression Matching
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* 10. Regular Expression Matching
* Implement regular expression matching with support for '.' and '*'.
*/
class Solution {