Skip to content

Commit bd2e407

Browse files
authored
Merge pull request #3 from efrat-dev/branch1
Adding 3 solutions files and an index.html file
2 parents 3f272e6 + efb3147 commit bd2e407

File tree

4 files changed

+170
-0
lines changed

4 files changed

+170
-0
lines changed

docs/index.html

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8" />
5+
<title>LeetCode Solutions – efrat-dev</title>
6+
<style>
7+
body {
8+
font-family: sans-serif;
9+
display: flex;
10+
height: 100vh;
11+
margin: 0;
12+
}
13+
#sidebar {
14+
width: 300px;
15+
background: #f4f4f4;
16+
padding: 1rem;
17+
overflow-y: auto;
18+
border-right: 1px solid #ddd;
19+
}
20+
#content {
21+
flex: 1;
22+
padding: 1rem;
23+
overflow: auto;
24+
}
25+
ul {
26+
list-style-type: none;
27+
padding-left: 1rem;
28+
}
29+
li {
30+
cursor: pointer;
31+
margin: 0.2rem 0;
32+
}
33+
pre {
34+
background: #1e1e1e;
35+
color: #dcdcdc;
36+
padding: 1rem;
37+
border-radius: 8px;
38+
overflow-x: auto;
39+
}
40+
</style>
41+
<!-- Highlight.js -->
42+
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/styles/github-dark.min.css">
43+
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/highlight.min.js"></script>
44+
<script>hljs.highlightAll();</script>
45+
</head>
46+
<body>
47+
<div id="sidebar"><strong>📁 תפריט קבצים</strong><div id="tree"></div></div>
48+
<div id="content"><em>בחר קובץ מהתפריט כדי לצפות בקוד.</em></div>
49+
50+
<script>
51+
const owner = "efrat-dev";
52+
const repo = "algo-ds-leetcode";
53+
const branch = "main";
54+
const baseUrl = `https://raw.githubusercontent.com/${owner}/${repo}/${branch}/`;
55+
56+
fetch(`https://api.github.com/repos/${owner}/${repo}/git/trees/${branch}?recursive=1`)
57+
.then(res => res.json())
58+
.then(data => {
59+
const files = data.tree.filter(item => item.type === "blob" && item.path.endsWith(".cs"));
60+
const treeData = buildTree(files.map(f => f.path));
61+
renderTree(treeData, document.getElementById("tree"));
62+
});
63+
64+
function buildTree(paths) {
65+
const root = {};
66+
for (const path of paths) {
67+
const parts = path.split("/");
68+
let curr = root;
69+
for (let i = 0; i < parts.length; i++) {
70+
const part = parts[i];
71+
if (!curr[part]) curr[part] = (i === parts.length - 1) ? path : {};
72+
curr = curr[part];
73+
}
74+
}
75+
return root;
76+
}
77+
78+
function renderTree(tree, container) {
79+
const ul = document.createElement("ul");
80+
for (const key in tree) {
81+
const li = document.createElement("li");
82+
if (typeof tree[key] === "string") {
83+
li.textContent = key;
84+
li.onclick = () => loadFile(tree[key]);
85+
} else {
86+
li.innerHTML = `📁 ${key}`;
87+
renderTree(tree[key], li);
88+
}
89+
ul.appendChild(li);
90+
}
91+
container.appendChild(ul);
92+
}
93+
94+
function loadFile(path) {
95+
const url = baseUrl + path;
96+
fetch(url)
97+
.then(res => res.text())
98+
.then(code => {
99+
document.getElementById("content").innerHTML = `
100+
<h3>${path}</h3>
101+
<pre><code class="language-csharp">${escapeHtml(code)}</code></pre>
102+
`;
103+
hljs.highlightAll();
104+
});
105+
}
106+
107+
function escapeHtml(text) {
108+
return text.replace(/[&<>"']/g, m => ({
109+
'&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;', "'": '&#039;'
110+
})[m]);
111+
}
112+
</script>
113+
</body>
114+
</html>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
public class Solution {
2+
public int Fib(int n) {
3+
if(n<=1)
4+
return n;
5+
int a=0, b=1;
6+
for(int i=2; i<=n; i++)
7+
{
8+
int sum=a+b;
9+
a=b;
10+
b=sum;
11+
}
12+
return b;
13+
}
14+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/**
2+
* Definition for a binary tree node.
3+
* public class TreeNode {
4+
* public int val;
5+
* public TreeNode left;
6+
* public TreeNode right;
7+
* public TreeNode(int val=0, TreeNode left=null, TreeNode right=null) {
8+
* this.val = val;
9+
* this.left = left;
10+
* this.right = right;
11+
* }
12+
* }
13+
*/
14+
public class Solution {
15+
public int MaxDepth(TreeNode root) {
16+
if(root==null)
17+
return 0;
18+
int left=MaxDepth(root.left);
19+
int right=MaxDepth(root.right);
20+
return int.Max(left, right)+1;
21+
}
22+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
public class Solution {
2+
public int Reverse(int x) {
3+
int reversed = 0;
4+
5+
while (x != 0) {
6+
int digit = x % 10;
7+
8+
// בדיקת חרגת טווח כאשר מנסים להוסיף ספרה נוספת
9+
if (reversed > (int.MaxValue / 10) || (reversed == int.MaxValue / 10 && digit > 7))
10+
return 0;
11+
if (reversed < (int.MinValue / 10) || (reversed == int.MinValue / 10 && digit < -8))
12+
return 0;
13+
14+
reversed = reversed * 10 + digit;
15+
x /= 10;
16+
}
17+
18+
return reversed;
19+
}
20+
}

0 commit comments

Comments
 (0)