Skip to content

Instantly share code, notes, and snippets.

@rowithcake
rowithcake / JsonSimpleLibraryExample1.java
Created October 16, 2014 02:03
1. Write JSON to file 2. Parse JSON from File
package com.javacodegeeks.java.core;
import java.io.FileWriter;
import java.io.IOException;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
public class JsonSimpleLibraryExample {
@rowithcake
rowithcake / MaxPoints.java
Created August 21, 2014 07:22
Max Points on a Line Given n points on a 2D plane, find the maximum number of points that lie on the same straight line. 27 / 27 test cases passed. Runtime: 492 ms
package luck;
public class MaxPoints {
class Point{
int x;
int y;
Point() {x=0; y=0;}
Point(int a, int b) {x = a; y = b;}
}
@rowithcake
rowithcake / solution.java
Created August 21, 2014 01:27
ZigZag Conversion The string "PAYPALISHIRING" is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility) P A H N A P L S I I G Y I R And then read line by line: "PAHNAPLSIIGYIR"
public class Solution {
public String convert(String s, int nRows) {
if (nRows <= 0)
return "";
if (nRows == 1){
return s;
}
s = s.trim();
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.Timer;