Skip to content

Commit

Permalink
Merge pull request #419 from m-oliv/patch-1
Browse files Browse the repository at this point in the history
- Added the reverse integer algo.
  • Loading branch information
ambujraj authored Oct 5, 2018
2 parents c4ab357 + 0210f0c commit be53ab8
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 2 deletions.
12 changes: 10 additions & 2 deletions CONTRIBUTORS.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Name: [Miftahul J.](https://github.com/jiadibo)<br/>
Name: [Miftahul J.](https://github.com/jiadibo)<br/>
Place: Indonesia<br/>
About: I'm moslem programmer<br/>
Programming Language: Java, kotlin, flutter<br/>
Expand Down Expand Up @@ -63,6 +63,7 @@ About: I am 3rd yearComputer science student at poornima college of engineering,
Programming Languages: C, C++,python</br>



Name: [Henry McCreery](github.com/hmccree)
Place: Portland, Oregon, USA
About: High school robotics team member project manager
Expand Down Expand Up @@ -395,22 +396,26 @@ About: I am a sophomore at IIT Mandi<br/>
Programming Languages: C, C++, JavaScript<br/>
Email: [email protected]


Name: [Samyak](https://github.com/samyak-sopho)
Place: Allahabad
About: Will do anything for free shirt
Programming Language: C++, JS, Java


Name: [Marlene Oliveira](https://github.com/m-oliv)
Place: Lisbon, Portugal
About: Software Engineer
Programming Language: Java, C, C#, Python, JavaScript, HTML, CSS


Name: [Trevin Edinger](https://github.com/ArkTrevelyan)
Place: Elkins, WV, USA
About: High School Graduate. Self teaching to be a programmer.
Programming Languages: Java, C.
Email: [email protected]


Name: [Tsaruk Alex](https://github.com/WildTiger404)<br/>
Place: Minsk, Belarus<br/>
About: I am a 3rd year stundent. I like traveling and events like this one<br/>
Expand All @@ -423,6 +428,7 @@ About: I am a 3rd Year Computer Science student at JSSATE Noida<br/>
Programming Languages: C, Java<br/>
Email: [email protected]


Name: [Darshan D V](https://github.com/darshandv)<br/>
Place: Mangalore, Karnataka ,India<br/>
About: I am a Computer Science student at NITK Surathkal<br/>
Expand All @@ -435,6 +441,7 @@ About: Btech student from JIIT<br/>
Programming Languages: C,C++,python3<br/>
email: [email protected]<br/>


Name: [Kartik Singh](https://github.com/Kartik212112)<br/>
Place: Patna,India<br/>
About: Btech student from IITP<br/>
Expand Down Expand Up @@ -705,4 +712,5 @@ Programming Languages: php, java, javascript<br />
Name: [Felipe](https://github.com/ja1felipe)<br/>
Place: Brazil<br/>
About: I am studying computer science.<br/>
Programming Language:Python, java<br/>
Programming Language:Python, java<br/>

26 changes: 26 additions & 0 deletions reverse/ReverseInteger.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
class ReverseInteger {
public static int reverse(int x) {
int reversed = 0;
int y = 0;

while(x!=0){
reversed = y * 10 + x % 10;
if((reversed - x % 10)/10 == y) {
y = reversed;
}else {
return 0;
}
x = x/10;
}

if(x < 0) {
return y * -1;
}

return y;
}

public static void main(String[] args) {
System.out.println(reverse(12345));
}
}
58 changes: 58 additions & 0 deletions sorting/mergesort.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package main

import (
"fmt"
)

func main() {
A := []int{3, 5, 1, 6, 1, 7, 2, 4, 5}
fmt.Println(sort(A))
}

// top-down approach
func sort(A []int) []int {
if len(A) <= 1 {
return A
}

left, right := split(A)
left = sort(left)
right = sort(right)
return merge(left, right)
}

// split array into two
func split(A []int) ([]int, []int) {
return A[0:len(A) / 2], A[len(A) / 2:]
}

// assumes that A and B are sorted
func merge(A, B []int) []int {
arr := make([]int, len(A) + len(B))

// index j for A, k for B
j, k := 0, 0

for i := 0; i < len(arr); i++ {
// fix for index out of range without using sentinel
if j >= len(A) {
arr[i] = B[k]
k++
continue
} else if k >= len(B) {
arr[i] = A[j]
j++
continue
}
// default loop condition
if A[j] > B[k] {
arr[i] = B[k]
k++
} else {
arr[i] = A[j]
j++
}
}

return arr
}

0 comments on commit be53ab8

Please sign in to comment.